How Sorting Arrays Works
The Sort method sorts the array according to values in specified columns. The syntax for this method is:
status = arrayobj.sort(attname = direction {, attname = direction})
Any attribute in the array with a simple data type or one of the allowable object types can be used as a sort key. Sort keys are listed in the order of significance, with the primary sort key listed first. Sort direction is specified as AS_ASC or AS_DESC.
The value of status is either of the following:
ER_OK
Specifies that the sort succeeded
ER_FAIL
Specifies that the sort failed. Failure is caused by such problems as specifying an incorrect attribute or sort order or attempting to sort non-sortable data.
The following example sorts the vlist array in descending order, using the category attribute as the primary sort key and title as the secondary sort key:
vlist.sort(category = AS_DESC, title = AS_DESC);
Attributes used in a sort can be of any simple data type, such as varchar or integer. The Sort method uses the object's Value attribute if the attribute is an object of one of the following types:
• DateObject
• FloatObject
• IntegerObject
• MoneyObject
• StringObject
No other object types are permitted as sort attributes.
If the array is displayed in a table field, the table field is automatically updated after the sort. For an example of sorting a table field, see
How You Can Sort Table Field Data Generically.
Last modified date: 12/20/2023