Sort records by object attribute

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:

Example database

If you want to know more about this command, you can refer to the 4D v16 R2 documentation.

Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.