Skip to main content
rupeshp0003
August 15, 2023
Question

Function or logic to sort an array of numbers.

  • August 15, 2023
  • 7 replies
  • 0 views

Do we have any function to sort an array of type integers in Ascending or Descending order (except a!sortInfo(), which did not help) 

For instance: I have an Array {1, 4, 6, 8, 5, 3} & I want to sort it in Ascending. 
So the O/P will be {1, 3, 4, 5, 6, 8} 

Thanks in advance!

7 replies

stewart.burchell
August 15, 2023

There's no (supported) sort function that we can use outside of the example I'm going to show you (I say "unsupported" because there *is* a function that exists but is flagged by Appian as being unsupported). 

a!sortInfo() is a system type that holds the instructions for how a sort operation should be applied. You need to use this within a datasubset. Here's how:

a!localVariables(
  local!array: { 1, 4, 6, 8, 5, 3 },
  local!fieldArray: a!forEach(
    items: local!array,
    expression: a!map(id: fv!item)
  ),
  local!datasubset: fn!todatasubset(
    arrayToPage: local!fieldArray,
    pagingConfiguration: a!pagingInfo(
      startIndex: 1,
      batchSize: - 1,
      sort: a!sortInfo(field: "id", ascending: true)
    )
  ),
  local!datasubset.data.id
)

Yes it's ugly and long-winded but it does the job.

gayatria0439
March 4, 2025

Why can't we go like this for sorting in ascending or descending order?

stefanhelzle0001
March 4, 2025

Because sort() is not part of the public API.

August 15, 2023

Take a look at 'Sort Utilities' plugin. 

anmolv0003
August 31, 2023
stefanhelzle0001
August 31, 2023

What is the difference?