First N Elements
Returns the first N elements of a list, optionally sorted.
The First N Elements action takes the first N elements of a list and returns them as a new list. You can also have those N elements sorted in the result. The input list is not changed.
Add the action
In the Process Designer toolbox, open List and pick First N Elements (or type First N in the search box).

Inputs and outputs
| Field | Direction | Type | Required | What to put / what you get |
|---|---|---|---|---|
| Input a list | Input | List of any type | Yes | The source list, for example [5,3,9,1]. |
| Input the number of elements to receive | Input | Integer | Yes | N, how many elements to take from the start. |
| Sorted: | Input | Option | Yes | Unsorted (keep the original order), Sorted ascendingly or Sorted descendingly. |
| Result | Output | List | Yes | The first N elements. |
Example
| Input a list | N | Sorted: | Result |
|---|---|---|---|
[5,3,9,1] | 2 | Unsorted | [5,3] |
[5,3,9,1] | 3 | Sorted ascendingly | [3,5,9] |
[5,3,9,1] | 3 | Sorted descendingly | [9,5,3] |
[5,3] | 10 | Unsorted | [5,3] (fewer elements than N is fine) |
[5,3] | 0 | Unsorted | [] |
["b","10","a","9"] | 4 | Sorted ascendingly | ["10","9","a","b"] |
[{"id":2},{"id":1}] | 1 | Unsorted | [{"id":2}] |
Good to know
The action takes the first N elements first, and only then sorts those N. It does not return the N smallest or largest values of the whole list. For a "top N" by value, Sort the list first and then use First N Elements with Unsorted.
- If N is larger than the list, you get the whole list; if N is
0or negative, you get an empty list. No error in either case. - Sorting compares numbers as numbers when every element is a number; otherwise all elements are compared as text (so
"10"comes before"9"). Whole and decimal numbers can be mixed:[1.5,-2,1]sorted ascendingly gives[-2,1,1.5]. - With Sorted ascendingly/descendingly, the result elements are converted: a list of objects comes back as a list of texts. Use Unsorted for lists of objects or data models.

