PROCESIO
OverviewPlatform ActionsIntegrations & DemosMarketplaceCustom ActionsDeveloperโ€™s Guide

Last N Elements

Returns the last N elements of a list, optionally sorted.

The Last N Elements action takes the last 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 Last N Elements (or type Last N in the search box).

The Last 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 end.
Sorted:InputOptionYesUnsorted (keep the original order), Sorted ascendingly or Sorted descendingly.
ResultOutputListYesThe last N elements.

Example

Input a listNSorted:Result
[5,3,9,1]2Unsorted[9,1]
[5,3,9,1]3Sorted ascendingly[1,3,9]
[5,3,9,1]3Sorted descendingly[9,3,1]
[5,3]10Unsorted[5,3] (fewer elements than N is fine)
[5,3]-1Unsorted[]

Good to know

The action takes the last N elements first, and only then sorts those N. It does not return the N smallest or largest values of the whole list. To get the N largest values, Sort the list ascending first and then use Last N Elements.

  • 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.
  • The elements keep their original order with Unsorted (the last element of the list is also the last in the result).
  • Sorting compares numbers as numbers when every element is a number; otherwise all elements are compared as text. A list of objects comes back as a list of texts when you choose a sorted option; use Unsorted for lists of objects or data models.

On this page