- Print
Learn how to use looping in Automations.
What is Looping?
Loops, or looping, repeatedly executes a set of logic until a specified condition is reached (in this case reaching the end of a list). In Automations, loops are provided a list of items. The loop will go through each item in the list, performing logic until it reaches the end of the list. For users familiar with programming, this is the same as a for-each loop.
How to use looping in Automations?
Click Automations in the navigation bar and then click +Create Automation or edit an existing automation. This will open the Automations editor.
In the automations action menu, click on the solid lines to select looping. Once the looping block has been opened, you'll need a list to enter into their loop. You can either manually create a list (for example, ["a","b","c"]), or use a Connector Function to return a list.
If an empty list is passed into the loop, it will return null and not run.
Two variables will automatically generate to use within the loop. The first variable, position, denotes the current iteration of the loop within the list and starts from 0 as the first position. The second variable, element, provides access to the current item in the list.
For example, you can use ["a","b","c"] as the list for your loop and create/update table as the logic performed in each loop. Here's a breakdown of the steps:
What's happening in this example is:
- The loop would go start with 0 as its position, "a" as its element, and then create/update the table.
- The loop would go to 1 as its position, "b" as its element, and then create/update the table.
- The loop would go to 2 as its position and "c" as its element, and then create/update the table.
- The loop would end.
The timeout is a minute for each automation. To learn more, read Automation Limits.