Sort list
Value resolver – Abstract
Purpose: This sorts the entries in a list provided as an input value in ascending or descending order. Hierarchical sorting criteria can optionally be defined, the value configuration of which is applied to all list entries.
The Sort list value resolver sorts the entries of a list present as input value, taking into account one or more hierarchical sort criteria with the following parameters:
The optional Compare value parameter defines a value resolver that is applied per list entry to determine the value that is decisive for sorting.
The Ascending option (checked by default) defines the direction of sorting. It can be unchecked if descending sorting is desired.
The return value is always a new list instance that lists all entries from the input value according to the sort order.
Special cases:
If the input value is 'No value' ($null), the return value is also 'No value' ($null).
If the input value is an empty list ([]), the return value is also an empty list ([]).
If the input value is a value that is not 'No value' ($null) but also not a list, then the return value is a list with this value as the only entry.
Configuration
|
The optional Compare value parameter can be used to define a value resolver that is applied to each entry in the input value to determine a comparison value for sorting.
|
|
|
The Ascending option is checked by default, which causes sorting in ascending order according to the Compare value. If sorting in descending order is desired, the Ascending option must be unchecked. |
|
|
Initially, the configuration of the Sort list value resolver provides for a single sort criterion.
The screenshot on the right shows a configuration with two search criteria:
|
|
|
►NOTE◄ If the configuration is carried out in a context that contains a tree view, these sorting criteria can be rearranged using drag & drop to adjust their priority in the hierarchy.
|
|
Examples
Simple use case: Sort simple values
In the following example, a list of simple values (in JSON notation: [1,8,6,null]) is output in descending order.
Runtime example:
Configuration:
|
In the context of an Execute with event action, the list defined statically for demonstration purposes is first defined as the reference object for the following event actions, as shown on the right:
|
|
Variant:
Based on the previous example, the statically defined list entries are now output in a random order.
Configuration: (As an adjustment within the previous configuration)
|
In the Sort list value resolver, a Compare value is now defined via the Random long value resolver. This value resolver randomly allocates a value from the value range for the Long data type, resulting in random sorting. ►NOTE◄ The Ascending option can be checked or unchecked. Since the sorting is random, this affects the order of the entries in the specific case. For once, however, this has no influence on the random sorting as a whole. Effectively, the order in the return value always appears randomly. |
|
Typical use case: Sort a list of objects by a specific property
|
Within an event handling the (stakeholders) variable refers to a list of Companies/Clients that are involved in a business object. When saving changes, the user will be informed about the companies involved. A separate notification appears for each company involved, reflecting selected address characteristics of the company according to a uniform scheme. Specifically, the companies are then listed in alphabetical order by the 'Name' (address.name1) property through a series of notifications of the 'Info' type. |
Runtime example:
|
Configuration:
|
The stakeholders variable is accessed here in the context of an Execute with event action. The image to the right shows only the event actions in the action block and (at the very top) the data type of the return value of the variable: Firmenkonto[]. For event actions, a list of the companies involved is therefore available as a reference object.
|
|
Special use case: Multi-stage sorting
The sorting of companies in the previous example is now adjusted in such a way that it is first sorted according to the country code (countryCode) and only then according to the company name.
Runtime example: (for the same list of companies involved as above)
Configuration:
|
To achieve multi-level sorting, only one additional sort criterion (per ►NOTE◄ As the screenshot on the right shows, this should be positioned at the top of the list. However, adding |
|
|
►IMPORTANT◄ The Object property value resolver for the ‘Country’ (countryCode) returns a value from the dynamic enumeration for the Country, type, which is used here directly as a sort criterion. Based on the sorting for the top criterion ‘Country’ in the specific example (DE < IE < IT), it could be assumed that the ‘Name’ (name) of the enumeration value is the deciding factor for the sorting. However, this assumption is not actually correct! The sort order for enumeration values is regulated differently depending on the execution context (server/client):
For the countries referenced in the example – ‘Germany’ (DE/82), ‘Ireland’ (IE/106) and ‘Italy’ (IT/109) – the order is always the same by chance, regardless of whether you sort by ‘Name’ or ‘Ordinal’. Even the localisation would result in the same sorting by chance. This would look different for a list with the countries ‘Germany’ (DE/28), ‘Austria’ (AT/14) and Switzerland (CH/215):
For a stable sorting with values from dynamic enumerations, it is therefore essential to explicitly decide how these values should be integrated. |
|
|
The screenshot on the right shows a variant of the above configuration, in which the ‘Name’ (name) field of the Country value is read from the ‘Country’ (address.countryCode) address field of the company account for the first sort criterion. The concatenated Upper case resolver ensures that the sorting takes place without differentiating between upper and lower case in the ‘Name’ field. The fact that all names in the enumeration are capitalised is also just a ‘fragile’ convention. ►NOTE◄ In the configuration on the right, the data field path that leads directly to the name of the enumeration value has been selected in the Object property resolver:
The same effect can be achieved by linking two or three Object property resolvers. |
|
|
The variant in the screenshot on the right looks very similar to the previous one, but does not directly address the ‘Name’ (name) field of the Country value from the ‘Country’ (address.countryCode) address field. The concatenated Upper case resolver recognises that the input value (Country type) is not a String and instead passes on its string image in upper case as a sort criterion.
|
|
|
The somewhat more complex configuration in the screenshot on the right aims to force a sorting according to the localisation for the Country referenced in the address for the Current locale in upper case (i.e. case-insensitive) both in the server context and in the client context:
For countries in the DACH region (as an example), the value resolver chain shown sends their default localisations for the Current locale ‘German’ (de) to the sorting. Specifically, these character strings:
However, the server and client sort the umlaut ‘Ö’ differently (ASCII code/‘OE’), so that Austria is categorised after Switzerland in the server context and between Germany and Switzerland in the client context. |
|