positionCollect[] = {1,2,3,4,5,6,7,8,9,10};
for (int i = 0; i < positionCollect.size(); i=i+2) { polygon[i/2] = new Point(positionCollect.get(i), positionCollect.get(i+1)); }
polygon is a Point Class type list, the Point class has two value x and y.
So basically I am using 10 numbers from List, create 5 object point (CDT) , and put into list polygon.
I am pretty new to appian I don't know expression rule can do the same thing? And unfortunately I can't use java plug-in to finished this so I have to write expression rules...
Discussion posts and replies are publicly visible
a!localVariables( local!positionCollect: {1,2,3,4,5,6,7,8,9,10}, local!polygonList: a!forEach( enumerate(length(local!positionCollect)/2)+1, type!Point( x: local!positionCollect[(fv!index*2)-1], y: local!positionCollect[(fv!index*2)] ) ), local!polygonList )
In Appian all functions and rules will return a value. In the code above, I have a list of positions defined as a list and then a polygonList which calls a!forEach() which will return a list. Also, the code above will only work if your positionCollect list is even.
You could structure the data differently and as the input provide a "list of lists" - that is a list of pairs of numbers, where each pair represents the x and y values:
a!localVariables( local!myListOfCoOrdinates: { { x: 1, y: 2}, { x: 3, y: 4}, { x: 5, y: 6}, { x: 7, y: 8}, { x: 9, y: 10} }, a!forEach( items: local!myListOfCoOrdinates, expression: type!Point( x: fv!item.x, y: fv!item.y ) ) )
or, indeed, you could leverage Appian's type casting capability:
a!localVariables( local!myListOfCoOrdinates: { { x: 1, y: 2}, { x: 3, y: 4}, { x: 5, y: 6}, { x: 7, y: 8}, { x: 9, y: 10} }, cast( 'type!{urn:com:appian:types:SJB}Point?list', local!myListOfCoOrdinates ) )
...so many cats, so many ways to skin them!
Thank you for your answers!!