At each 4D release, object fields become more and more powerful.
A new 4D command for sorting your record selections according to one or more attributes is now available with 4D v16 R2. The new command ORDER BY ATTRIBUTE works the same as the command ORDER BY; you just have to pass an attribute path by which you want to order your selection – easy!
Lets’ take an example: you want to sort the current selection by age (descending) and then by name (ascending).
Default order is:
{"LastName":"Giorgio","age":33,"client":true},
{"LastName":"Sarah","age":42,"client":true},
{"LastName":"Wesson","age":44,"client":true},
{"LastName":"Kerrey","age":44,"client":true}
If you execute:
ORDER BY ATTRIBUTE([Customer];[Customer]OB_Info;"age";<;[Customer]OB_Info;"LastName";>)
Records are in the following order:
{"LastName":"Kerrey","age":44,"client":true},
{"LastName":"Wesson","age":44,"client":true},
{"LastName":"Sarah","age":42,"client":true},
{"LastName":"Giorgio","age":33,"client":true}
Note: You can mix the ORDER BY and ORDER BY ATTRIBUTE commands to define the record order.
Download the following database to find more examples:
If you want to know more about this command, you can refer to the 4D v16 R2 documentation.