PROCESIO
OverviewPlatform ActionsIntegrations & DemosMarketplaceCustom ActionsDeveloperโ€™s Guide

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).

The First N Elements action properties: Input a list, Input the number of elements to receive, Sorted and Result

Inputs and outputs

FieldDirectionTypeRequiredWhat to put / what you get
Input a listInputList of any typeYesThe source list, for example [5,3,9,1].
Input the number of elements to receiveInputIntegerYesN, how many elements to take from the start.
Sorted:InputOptionYesUnsorted (keep the original order), Sorted ascendingly or Sorted descendingly.
ResultOutputListYesThe first N elements.

Example

Input a listNSorted:Result
[5,3,9,1]2Unsorted[5,3]
[5,3,9,1]3Sorted ascendingly[3,5,9]
[5,3,9,1]3Sorted descendingly[9,5,3]
[5,3]10Unsorted[5,3] (fewer elements than N is fine)
[5,3]0Unsorted[]
["b","10","a","9"]4Sorted ascendingly["10","9","a","b"]
[{"id":2},{"id":1}]1Unsorted[{"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 0 or 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.

On this page