Tech Tip: ORDA Querying a Single Record
PRODUCT: 4D | VERSION: 21 | PLATFORM: Mac & Win
Published On: January 13, 2026
When performing a query using ORDA, the result is an entiry selection. Even when querying for a unique field where only one record (entity) will be returned, the result will still be an entity selection.
To specify and interact with the first/only record it can be referenced using the first index (0):
However, accessing an index that does not exist will generate an error. This means that if the query has no results and the entity selection is empty, trying to access the first entity through index 0 will create an error. For general cases when accessing an index of an entity selection, the length of the entity selectiontion can be checked through the .length attribute.
In this case, where a single record is expected, the .first() function can be used instead:
With the .first() function, if the entity selection is empty, it will instead return a Null and avoid an error for the line, but a check for Null will need to be performed afterwards and prior to attempting to interact with an entity.
| var $result : Object $result:=ds.Table_1.query("ID = :1"; 40) // $result contains an entity selection of Record with ID = 40 |
To specify and interact with the first/only record it can be referenced using the first index (0):
| var $result : Object $result:=ds.Table_1.query("ID = :1"; 40)[0] // $result contains the entity with ID = 40 |
However, accessing an index that does not exist will generate an error. This means that if the query has no results and the entity selection is empty, trying to access the first entity through index 0 will create an error. For general cases when accessing an index of an entity selection, the length of the entity selectiontion can be checked through the .length attribute.
In this case, where a single record is expected, the .first() function can be used instead:
| var $result : Object $result:=ds.Table_1.query("ID = :1"; 40).first() // $result contains the entity with ID = 40 |
With the .first() function, if the entity selection is empty, it will instead return a Null and avoid an error for the line, but a check for Null will need to be performed afterwards and prior to attempting to interact with an entity.