Skip to main content
October 28, 2021
Question

Sort values in Constant

  • October 28, 2021
  • 5 replies
  • 0 views

Hello All,

I have constant with holds distinct values of usernames.

The constant USER_GROUP has the values {gamma, beta, alpha}

Earlier we had a sort() function which would sort the data for us, but this function is no longer available.

In documentation I see only a!sortInfo available which is useful to sort the data from DB and I cannot use any utilities as well for sorting the data.

So can anyone suggest an alternate way to sort the data in a constant to {alpha, beta, gamma}

 

a!localVariables(
  local!sendingName: getdistinctusers(cons!USER_GROUPS)
  local!sendingName
)

Thanks & Regards

Girish Katti

5 replies

selvakumark
Participating Frequently
October 28, 2021

Hi,

This is one possible way for sorting:

todatasubset(
  a!forEach(
    items: { "gamma", "beta", "alpha" },
    expression: { value: fv!item }
  ),
  a!pagingInfo(
    startIndex: 1,
    batchSize: - 1,
    sort: a!sortInfo(field: "value", ascending: true())
  )
).data.value

October 28, 2021

Thankyou very much for sharing the information.

peter.lewis
Employee
October 28, 2021

This is also one of those utility rules that I often create / import before any project and reuse!

stefanhelzle0001
Brainy
October 28, 2021

The function sort() was always private API and undocumented. The only way I am aware of, is to turn the list into a list of dictionaries and then use todatasubset() for sorting.

Code similar to this should create the list of dictionary.

a!foreach(
  items: getdistinctusers(cons!USER_GROUPS),
  expression: a!map(user: fv!item)
)

October 28, 2021

Thankyou very much for sharing the information.