webCOMAND

POSITION_IN()

Return the index of the object within a collection.

To get the index of an object referenced by a field, use the object method .POSITION_IN().

Prototype

integer POSITION_IN(cpath $cpath, string $field = NULL)

Parameters

  • cpath - cPath, OID, DOID (ie. 123D) or UUID that references a:
    • Folder - If a folder or object that extends folder is specified and no field parameter is specified, the Folder's Contents field will be assumed.
    • Object - If a non-folder object is specified, then the field must be specified.
  • field - Optional Identifier of an ordered collection field, which is required when the cpath parameter references an object that is not a Folder.

Return

An integer that represents the object's index into the ordered collection.  If the object is not in the collection, NULL is returned, which can be useful when testing for an object's membership in a specific field in a WHERE clause or cPath filter.

Examples

Folder cPath Example

SELECT * FROM WebPage ORDER BY POSITION_IN(/Website/Content)

Folder OID Example

SELECT * FROM WebPage WHERE POSITION_IN(123)

Collection Field in cPath Example

SELECT * FROM WebPage ORDER BY POSITION_IN([:Menu AND OID=456].WebPages)

Collection Field as Parameter Example

SELECT * FROM WebPage ORDER BY POSITION_IN(456, WebPages)

Related

.POSITION_IN(), IN_FOLDER()