Hi folks,
Can anyone please tell me the difference between load(),with(), a!localvariable and a!refreshvariable functions. In what different scenarios are all these used. Is a!localvariable replacement of load and with both ?
It would be better if someone explain them using a code snippet.
Discussion posts and replies are publicly visible
a!localVariables() completely replaces load() and with().
interesting position...I'd be interested in how you'd implement a nested a!forEach() where the inner loop requires a value from each outer loop. Obviously one option would be to write a rule that passed the entire fv!item, from which you'd extract the outer value and all the inner values...but if you wanted to do this without such a helper rule, you could use a with() to define a local!variable that you could set (and re-set) for each outer loop and that is now made available to the inner loop.
Wait, are you saying that couldn't be done with a!localVariables()? Why?
Because you can't assign a value to a local!variable from within the scope of the a!forEach() - or, if you can, I'm not seeing how that's done. Here's what I've just experimented with. First is what works using a with():
a!localVariables( local!myNestedArray: { { {record: 1, attributes: {"A","B","C"}}, {record: 2, attributes: {"D","E","F"}} }, }, a!forEach( items: local!myNestedArray, expression: with( local!currentItem: concat("SJB/", fv!item.record), a!forEach( items: fv!item.attributes, expression: { local!currentItem, fv!item } ) ) ) )
...and secondly here's what I've tried to do just using local!variables (which I can't get to work):
a!localVariables( local!myNestedArray: { { {record: 1, attributes: {"A","B","C"}}, {record: 2, attributes: {"D","E","F"}} }, }, local!currentItem: null, a!forEach( items: local!myNestedArray, expression: { local!currentItem: fv!item.record, a!forEach( items: fv!item.attributes, expression: { local!currentItem, fv!item } ) } ) )
Arguably (and I might take that position for more a more sophisticated transformation in the inner loop) you'd have a helper rule. And maybe that's best practice, but I'm always (!) suspicious when someone is definitive in their reply! ;-)
Found your problem... you replaced with(), with nothing, instead of a!localVariables()...Stewart Burchell
should be:
a!localVariables( local!myNestedArray: { { {record: 1, attributes: {"A","B","C"}}, {record: 2, attributes: {"D","E","F"}} }, }, local!currentItem: null, a!forEach( items: local!myNestedArray, expression: a!localVariables( local!currentItem: fv!item.record, a!forEach( items: fv!item.attributes, expression: { local!currentItem, fv!item } ) ) ) )