Hi,
We have a datetime field array and want to sort it in ascending order. Please let me know how to do it. If you have any code snippet please share which will be helpful.
Thanks in advance.
Discussion posts and replies are publicly visible
From where are we getting the data. If it is from the database, we can apply sorting with paging. Else, we can try converting the data to the data subset and then apply sorting.
As 'yoga' mentioned...if the data is in a database you'd be better off using the SQL's 'ORDER BY' to apply the sort before retrieving into Appian.
In Appian you can use the 'sort' capability of a datasubset, something like this:
load( local!dataToSort: a!forEach( items: ri!dateTime, expression: {item: fv!item} ), fn!todatasubset( local!dataToSort, a!pagingInfo( startIndex: 1, batchSize: -1, sort: a!sortInfo( field: "item", ascending: true ) ) ).data.item )
Utilize the "ORDER BY" is you want to sort at database layer itself
or convert it into a datasubset to use a!sortInfo() function on your datetime field
I had an array of time values that I needed to appear in ascending order.
This worked for me:
local!timingChoices: sort(index(local!sourseList, "timing_val", null))
sort is a hidden function, it does the trick, but shouldn't be used for serious stuff.