Skip to main content
Participating Frequently
Jun 12, 2023 9:43 AM UTC
Question

Function

What Is a function for showing array itoem in ascending or descending

    9 replies

    harshitb6843
    Brainy
    Jun 12, 2023 9:45 AM UTC

    There is no direct function. You can use todatasubset() paired with sortInfo() to get the desired result.

    a!localVariables(
      local!array: a!forEach(
        items: ri!array,
        expression: { utls: fv!item }
      ),
      todatasubset(
        arrayToPage: local!array,
        pagingConfiguration: a!pagingInfo(
          startIndex: 1,
          batchSize: - 1,
          sort: a!sortInfo(field: "utls", ascending: ri!isAscending)
        )
      ).data.utls
    )

    mathieud0001
    Genius
    Jun 12, 2023 10:54 AM UTC

    This is the best way.

    sanchitg0002
    Inspiring
    Jun 12, 2023 10:26 AM UTC

    You can also use Sort Utilities plugin, only if you are okay with dependency on a custom plugin.

    However, I believe it is high time Appian should introduce OOTB documented version of the hidden sort() function, instead of forcing us to first convert the data into key value pairs and then use todatasubset and pagingInfo just to apply sorting to a list of numbers.

    Hidden sort() function:

    harshitb6843
    Brainy
    Jun 12, 2023 10:30 AM UTC

    I hope you know you shouldn't be using undocumented functions. 

    sanchitg0002
    Inspiring
    Jun 12, 2023 10:37 AM UTC

    Yupp! I know that pretty well. Just one of many requests which we have from Appian.