I have a variable that contain list of items, items are ;-
year , category , value
2024, cap internal , 20
2024, cap external, 60
2024, cap material, 50
2025, exp internal , 20
2025, exp external , 30
2025, exp material , 40
I want to sort this like :-
Discussion posts and replies are publicly visible
Use the todatasubset() function. Find an example here: https://docs.appian.com/suite/help/24.4/fnc_scripting_todatasubset.html#examples
a!localVariables( local!input: { { "2024, cap internal , 20", "2024, cap external, 60", "2024, cap material, 50", "2025, exp internal , 20", "2025, exp external , 30", "2025, exp material , 40" } }, local!dictionary: a!forEach( local!input, a!localVariables( local!itemVal: split(fv!item, ","), a!map( year: local!itemVal[1], category: local!itemVal[2], value: local!itemVal[3] ) ) ), local!sorted: todatasubset( local!dictionary, a!pagingInfo( 1, - 1, { a!sortInfo(field: "year", ascending: true()), a!sortInfo(field: "value", ascending: false()) } ) ).data, local!sorted )
For better readability
Hello, below is solution for your problem.
a!localVariables( local!category:{ "2024,cap internal,20", "2024,cap external,60", "2024,cap material,50", "2025,exp internal,20", "2025,exp external,30", "2025,exp material,40" }, local!data:a!forEach( items: local!category, expression: split(fv!item,",") ), local!finalData: a!forEach( items: local!data, expression: a!map( "year":fv!item[1], "category":fv!item[2], "value": fv!item[3] ) ), todatasubset( local!finalData, a!pagingInfo( 1, 10, a!sortInfo( field: "value", ascending: false() ) ) ).data )
And if you want to sort by year then just
change "value" to "year" in the below code.
a!sortInfo( field: "value", ascending: false() )