« Back to Product

Documentation

IPS_FindObjectIDByIdent

 int IPS_FindObjectIDByIdent (string $Ident, int $ParentID) 

Parameters

Ident

Object ident to search for

ParentID

ID of the object whose direct children are searched

Returns

ID of the found object, otherwise 1 (invalid ID)

Description

The function searches the direct children of the object with the ID ParentID for the object with the ident Ident and returns its ID. Deeper nested objects are not searched. The comparison is exact (case-sensitive). 0 (root) is also allowed as ParentID.

Unlike IPS_GetObjectIDByIdent, the function does not fail if no matching object exists, but returns the invalid ID 1. It is therefore suited to check whether an object with a certain ident already exists without having to suppress a warning.

Warning

If no object is found, the result is 1, not FALSE or 0. Valid object IDs are always greater than or equal to 10000, so the result should be compared with 1 explicitly.

If Ident is an empty string, the function fails with "Ident cannot be empty". If the object ParentID does not exist, it fails with "Object #... does not exist".

See also: IPS_FindObjectIDByName, IPS_SetIdent

Example

$id = IPS_FindObjectIDByIdent("Temperature", 12345);
if ($id === 1) {
    echo "No object with the ident 'Temperature' found";
} else {
    echo "Found: #" . $id;
}
Any questions?