Hi Everyone,
I have a requirement where i can reuse local variable array. For Example
a!localvariable(
local!iterations:{1,2,3},
local!value,
a!foreach(
items:local!iterations,
expression{
append(
fv!index
)}))
The output i need is
1st Iteration
1
2nd Iteration
2
3rd Iteration
3
But the output the code is generating is
3.
I thought that local variable should be append with the value and can use for next iteration but it is initializing every time with null value rather than appendvalue. Could you please help me to get the output i need
Thanks In Advance!!!
Discussion posts and replies are publicly visible
You CANNOT update the value of a variable in an expression rule. To update a variable value, you need a user interaction to happen and that is why it is only possible in an interface or a PM. To achieve your use case, you can make this small tweak in your code and it should work.
a!localVariables( local!iterations: { 1, 2, 3 }, local!value, a!forEach( items: local!iterations, expression: enumerate(fv!index)+1 ) )
Thanks!! But its not the exact code or the way that i need, I just want to reuse the variable in next iteration which is updated. But Thanks for the Info
I think you have a fundamental misunderstanding of what local variables are and what they do (and what they don't do). And what happens when functions act upon them.
A slightly simpler example: If you have a local variable of "local!asdf: {1, 2, 3}" for instance - and you call append() on it: the result of append() is simply an output of the resulting value, it does not (nor would it ever) modify the original local variable it was acting upon.