Loop

A simple summary on how to use the Map step in a Flow

Overview

Loop allows you to run the same sequence of steps over each object in an array (or list) of objects. For example, you might want to query a segment of users from your database and send each user a message. To do this, you could use a Service step to query your users, then a Loop step to iterate over each user, followed by a Sendgrid step to send each user an email.

To add a Loop to your recipe, click the "+" button in your recipe editor and choose Loop from the step selector drawer. Then, click the dropdown button under "Select array to loop over" to invoke the variable menu and choose the array you want to run the sequence on.

The Loop step expects an array of objects as its input. When the Loop runs, it loops through the array and appends the items of each step within the Loop to the output on each index.

For example, if you have a Loop step to calculate the tax on an array of retail products, like this:

The output of the function step in the above example, labeled tax, will be appended on each array item. Here's an example input and output:

Input

[
{
amount: 10
},
{
amount: 100
},
]

Output

[
{
amount: 10,
tax: 1.3
},
{
amount: 100,
tax: 13
},
]

Referencing data within a Loop

To use the currentValue (current element being processed in the array) in any of the Loop's steps, you can use $item

Note: All steps in your Loop step have access to data from all upstream steps in your Flow. For example, if you had a Function step before your Loop step, you'd be able to access the data from it within your Loop routes.