At times you may want to loop over a list of elements in the pipeline and perform other operations. Currently the looping capability is available on a field pipeline only.
Looping a list from function
For functions that return a list as output, there is no need to loop through explicitly using Find Value function. Loops are executed automatically when the pipeline sees a multivalued field. All nodes succeeding the multivalued field are considered part of the loop, until a Syncari node, a destination or any one of the special nodes that can handle multivalued fields directly is encountered. (ex: Join, Sort, Reverse, Last).
Lets take an example where we want to increment all the values in a list.
The loop is executed node by node. For example, if the multivalued field has [1,2,3]
as values and there was an increment by 2
node after that and a decrement by 1
next, increment by 2
would be executed for all items in the field , resulting in [3,4,5]
and then decrement by 1
would be executed on this resulting multivalued field , producing [2,3,4]
If the output of a function is not directly a list and instead saved in context, or if you want to loop through a list from a custom action result, like described in next section, then use Find Value function.
Looping a list from custom action
When you have a custom action returning json response containing an array, you can loop over each of the elements from in the pipeline. This can be done using the Find Value function. When accessing the results from custom action use the token.
Let's say the Get Transactions custom action returns a json that has a list of transactions as shown below,
{
transactions : [
{ id : "123", amount : 23},
{ id : "234", amount : 34}
]
}
In this case, to loop over all elements in the result list, use the Find Value function after the custom action node. The field name to access. the list would be a token - {{Action Result From Get Transactions.transactions}} , where transactions is an array in the json response.
If the response from the custom action is an array instead of an object, then you can access it directly in the Find Value function using the token {{Action Result From Get Transactions}}.
[
{ id : "123", amount : 23},
{ id : "234", amount : 34}
]
Looping a list from Lookup External Record function
Lookup External Record function is special, unlike all other functions it makes an external api call. If you want to loop over the elements from the result list, it follows the same instructions as custom action described above. The only difference being the name of the field - use the token {{Records from <node-name>}} instead.