Hi,
I have an array of CDT ABC:
{
{ Id: 111111, position: L1}
{ Id: 22222, position: R2}
{ Id: 333, position: L2}
{ Id: 44, position: R1}
{ Id: 555, position: L3}
{ Id: 666, position: R3}
}
Now I need to sort this array as
Can someone give me some hint?
Thanks,
Peiran
Discussion posts and replies are publicly visible
Pass it through the toDataSubset() function, using a sort parameter that sorts on the column you'd like. If you'll be doing this all the time but on different CDTs, I'd suggest you set up an expression rule that takes in the CDT to sort, the field you want to sort on, and true/false value for whether the sort should be in ascending or descending order.
Few ways to do this, here is an example that first finds how many L and R values are in the CDT then uses that count to loop each and build a sorted CDT:
a!localVariables( local!cdt: { { Id: 111111, position: "L1"}, { Id: 22222, position: "R2"}, { Id: 333, position: "L2"}, { Id: 44, position: "R1"}, { Id: 555, position: "L3"}, { Id: 666, position: "R3"} }, local!countPositionL: count(where(a!forEach( items: local!cdt.position, expression: if(search("L",fv!item,1)>0,true,false) ))), local!countPositionR: count(where(a!forEach( items: local!cdt.position, expression: if(search("L",fv!item,1)>0,true,false) ))), a!flatten( { a!forEach( items: 1+enumerate(local!countPositionL), expression: index( local!cdt, wherecontains(concat("L",fv!index),a!foreach(items:local!cdt.position, expression: tostring(fv!item))), {} ) ), a!forEach( items: 1+enumerate(local!countPositionR), expression: index( local!cdt, wherecontains(concat("R",fv!index),a!foreach(items:local!cdt.position, expression: tostring(fv!item))), {} ) ) } ) )
Ah yes, todatasubset() will work for this scenario as well since the desired sort is in fact in alphabetical order!
a!localVariables( local!cdt: { { Id: 111111, position: "L1"}, { Id: 22222, position: "R2"}, { Id: 333, position: "L2"}, { Id: 44, position: "R1"}, { Id: 555, position: "L3"}, { Id: 666, position: "R3"} }, todatasubset( local!cdt, a!pagingInfo(1,-1,a!sortInfo("position",true)) ).data )
Yeah, this is what I was thinking of.
Mike Schmitt, Chris,
All your solution are working!
Thanks!
Thanks for confirming