I want to print 2D array
a!localVariables( local!a:{{1,2}, {3,4},{6,7}}, a!forEach( items: local!a, expression: fv!item ))
This will give below result
123467
But I want to print the result in below form
1,23,46,7
Discussion posts and replies are publicly visible
In your example above the expression your a!foreach will run on each iteration, is just the value e.g., {1,2}, so that pair/array will be displayed however is appropriate for that type of value. If you have some specific expression rule or function that displays that type of value how you want, then you should use that instead of just the value. For example, instead of just expression:fv!item, use expression:joinArray(fv!item, ","). docs.appian.com/.../fnc_array_joinarray.html
The issue here is that the array is being flattened and a!foreach() sees it as 6 items, vs 3 pairs of 2 items each. I'm not sure if we can unflatten it directly within a primitive data type.
Are you able to control the array, such as formatting it to key/value pairs? Such as:
a!localVariables( local!a: { {value: {1,2}}, {value: {3,4}}, {value: {6,7}} }, a!forEach( items: local!a, expression: joinarray(fv!item.value,",") ) )
Or, do we know that this data will always be an array of 2-valued nested arrays? Such as:
a!localVariables( local!a: {{1,2},{3,4},{6,7}}, a!forEach( items: 1+enumerate(count(local!a)/2), expression: joinarray( a!foreach( items: {fv!item*2-1,fv!item*2}, expression: index(local!a,fv!item,null) ), "," ) ) )
We can nix the nested a!foreach() in the second example above as well:
a!localVariables( local!a: {{1,2},{3,4},{6,7}}, a!forEach( items: 1+enumerate(count(local!a)/2), expression: joinarray(index(local!a,{fv!item*2-1,fv!item*2},null),",") ) )
Thanks Scott this helped me.
Thanks Chirs for enhancing my knowledge.