I have the following code:
a!localVariables( local!a: { 1,2 }, local!b: { 3, 4, 5 }, a!forEach( items: local!a, expression: 'type!{urn:com:appian:types:XZY}Employee'( ID: fv!item,Value: fv!item,Field: a!foreach (items:local!b[fv!index], expression: fv!item) ) ))
and I want to obtain:
{1,1,3}
{1,1,4}
{1,1,5}
{2,2,3}
{2,2,4}
{2,2,5}
(All outputs must be of type!Employee)
What is the best way to obtain that result, because my code is only generating values for the first one.
Discussion posts and replies are publicly visible
You need to do this the other way around. Iterate over the local!b list:
a!localVariables( local!a: { 1 }, local!b: { 3, 4, 5 }, a!forEach( items: local!b, expression: 'type!{urn:com:appian:types:XZY}Employee'( ID: local!a, Value: local!a, Field: fv!item ) ) )
That should result in a list of type 'Employee' with the fields set as required.
Both are arrays, think local!a as {1,2,3,4}, not just 1 value. I've enhanced the question with this particular mention
Ok, understood.
So, you'll need to nest your a!forEach() loops. The outer one will select a value from local!a. You need to hold that value as a local!variable to be used in the inner loop:
a!localVariables( local!a: { 1,2 }, local!b: { 3, 4, 5 }, a!forEach( items: local!a, expression: with( local!temp: fv!item, a!forEach( items: local!b, expression: 'type!{urn:com:appian:types:XZY}Employee'( ID: local!temp, value: local!temp, field: fv!item ) ) ) ) )