In Appian, suppose you have a list of a!map objects with fields name and id. How can you sort this list alphabetically by the name field?
In Appian, suppose you have a list of a!map objects with fields name and id. How can you sort this list alphabetically by the name field?
Answer
In Appian, we can use todatasubset() with a!pagingInfo() and a!sortInfo() to sort the list.
Appian Expression
Step-by-step explanation
Step 1:
We have a list containing four maps. Each map has an id and a name.
ID | Name |
|---|---|
1 | Interface |
2 | Process Model |
3 | Records |
4 | Data type |
The names are not in alphabetical order. The goal is to sort by name while each item keeps its own id, so the maps move as whole units.
Step 2: What does a!sortInfo() do?
This tells Appian which field to sort and in which direction.
field: "name"means to compare thenamevalues in each map.ascending: true()means to sort alphabetically from A to Z.
If you change it to ascending: false(), the names are sorted in reverse alphabetical order.
Step 3: What does a!pagingInfo() do?
a!pagingInfo() specifies how many items to retrieve, where to start, and how to sort them.
startIndex: 1starts from the first item.batchSize: -1requests all items rather than a limited batch.sortspecifies the sorting rule we defined in Step 2.
Paging information is usually used to retrieve a specific page of data, but it can also configure sorting.
Step 4: What does todatasubset() do?
todatasubset() takes two inputs:
local!data: the original list we want to sort.a!pagingInfo(): the instructions that tell Appian how to sort and retrieve the items.
Appian applies the sorting instructions and returns a DataSubset, which holds the resulting data along with paging information.
Step 5: Why do we use .data?
todatasubset() returns a DataSubset, so .data is what extracts the sorted list of maps from it.
Output:

Interested in more coding challenges ? visit : https://appianverse.com/coding
Try it yourself
Change the inputs or the expression and run it to see what it returns.
Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms
Check yourself
Question 1 of 3, on what the answer above covers.
- 1.You sort the maps in this question with
a!sortInfo(field: "name")and leave outascending. All four maps are returned. Which name comes first? - 2.
todatasubset()gets a list of four maps anda!pagingInfo(startIndex: 1, batchSize: 2). What istotalCountin the result? - 3.The maps in this question are sorted by
namefrom A to Z. The paging usesstartIndex: 3andbatchSize: 2. Which names are returned?