Loop
Before you start
A Loop runs the same steps once for every item, such as every line of a purchase order. It has two paths: Each item holds the steps to repeat, and After loop continues when the last round is done.
When should I use a Loop?
Section titled “When should I use a Loop?”Use a Loop to do one thing per record: email each vendor, update each line. For a bulk save, a Record manager with Batch create or Batch update is faster than a loop.
Add a Loop
Section titled “Add a Loop”- Make the list first. Add a Load data step above and name its list, for example
openOrders. - Click + and choose Loop.
- Under Repeat for, choose Each record in a list.
- Under Which list?, choose the list.
- Click + on the Each item line and add the steps to repeat.
Inside the loop, the list’s name means the current record. In Insert data it shows as Current item in the list’s name.
What are the three ways to repeat?
Section titled “What are the three ways to repeat?”| Choice | What it does | Setting |
|---|---|---|
| Each record in a list | One round per record of a list made above | Which list? |
| Each item inside a field | One round per item of a list field on the current record, such as the lines of an API reply | Which field? |
| A number of times | Rounds count from 1 to N | How many times?, Name this index |
For A number of times, the count is a Smart Script or a number. Decimals are cut, and 0 or less means no rounds. Read the round number as the name you gave, then index.
How do I loop over a very large list?
Section titled “How do I loop over a very large list?”Turn on Process in pages. It applies to a list made by Load data. With paging on, the loop reads the list from the database one page at a time.
| Setting | What it does |
|---|---|
| Page size | Records per page. Leave it empty for the standard page |
| Stop after | Total records to process. Leave it empty to process them all |
Worked example: remind every vendor
Section titled “Worked example: remind every vendor”Sara loads the vendors whose contract ends this month into expiringVendors. A Loop goes over that list. In Each item, a Send email addresses the current vendor’s contact. After the loop, a Record manager marks the batch as notified.
What should I watch for?
Section titled “What should I watch for?”- Save what you need from a loop over records with a Record manager inside the loop. A loop that counts keeps what its rounds made.
- A Terminate inside the loop ends the whole workflow.
- Make the list in a Load data step on the same path above the loop.
- Put a Record manager with Batch create or Batch update before or after the loop, so the list is saved once.