The entitySelection.max( ) method returns the highest (or maximum) value among all the values of attributePath in the entity selection. It actually returns the value of the last entity of the entity selection as it would be sorted in ascending order using the entitySelection.orderBy( ) method.
If you pass in attributePath a path to an object attribute containing different types of values, the entitySelection.max( ) method will return the maximum value within the first scalar type in the default 4D type list order (see collection.sort( ) description).
entitySelection.max( ) returns undefined if the entity selection is empty or attributePath is not found in the object attribute.
An error is returned if:
- attributePath is a related attribute,
- attributePath designates an attribute that does not exist in the entity selection dataclass.
We want to find the highest salary among all the female employees:
C_OBJECT($sel)
C_REAL($maxSalary)
$sel:=ds.Employee.query("gender = :1";"female")
$maxSalary:=$sel.max("salary")