Good afternoon,
I am trying to compare in a foreach loop a data with the previous iteration, but I am not able to access this iteration, is there any way?
I need to sort a list, but if there are two equal values they have the same order, with the array{ name:"aaaaa", valor:2 name:"bbbbb", valor:10 name:"ccccc", valor:10 name:"ddddd", valor:10 name:"eeeee", valor:45}get as a result{ name:"aaaaa", pos:1 name:"bbbbb", pos:2 name:"ccccc", pos:2 name:"ddddd", pos:2 name:"eeeee", pos:3}I am trying to save the pos outside of the foreach in a local variable, or recover the value saved in pos of the previous item
Thank you very much
Discussion posts and replies are publicly visible
This will fulfil your requirement if I understood your query correctly
a!localVariables( local!data: { a!map( name: "aaaaa", valor: 1 ), a!map( name: "bbbbb", valor: 10 ), a!map( name: "ccccc", valor: 10 ), a!map( name: "ddddd", valor: 10 ), a!map( name: "eeeee", valor: 45 ) }, local!uniqueValors: union(local!data.valor, tointeger({})), local!valorIndices: createdictionary( local!uniqueValors, enumerate(length(local!uniqueValors))+1 ), a!forEach( items: local!data, expression: a!map( name: fv!item.name, pos: property(local!valorIndices, tostring(fv!item.valor), null) ) ) )
The problem with that, and please correct me if I'm wrong, is that it will only work if the 'valor' values are ordered.In adition, never seen a 'Bean' Appian type as shown in the property function that you are using!!!!!!!!
yes for this the values should be ordered
to use Aryan code, add this as a new variable right after local!data, and use that new variable:
todatasubset( arrayToPage: local!data, pagingConfiguration: a!pagingInfo( startIndex: 1, batchSize: -1, sort: a!sortInfo( field: "valor", ascending: true ) ) )
if you see name in the code snippet refresh, edited to "valor".