Loop
Overview
Section titled “Overview”The Loop operation runs the actions in Do once for every element of Items, for example for every row of a CSV file or every entry of an API response.
Items |
Iterations | item |
|---|---|---|
a number, e.g. 5 |
5 | {{item.value}} = 1 … 5 |
Range(10,15) |
6 | {{item.value}} = 10 … 15 |
a JSON list, e.g. ["a","b"] or {{Query.Response.Body.items}} |
per element | objects stay objects ({{item.id}}), simple values are in {{item.value}} |
path of a .json file with a list |
per element | as above |
path of a .csv file or CSV text over several lines |
per row | {{item.<column name>}} |
| anything else | 1 | {{item.value}} = the text |
CSV: the separator is ; if the first line contains one, otherwise ,. The first line is the header, unless one of its cells is a whole number; without a header the columns are named col0, col1, … Quoted values containing the separator are not supported.
In the diagram of the workflow editor Loop has a form: Items (Items, values as above; inside, {{item}} and {{index}} apply), At most rounds, Stop after errors and Pause between rounds (ms). Drag values in from the test view.
Structure
Section titled “Structure”{ "Type": "Loop", "Name": "WriteEachCustomer", "Parameters": { "Items": "C:\\RUNOS\\Data\\customers.csv", "Do": [ { "Type": "SMTP", "Name": "Write", "Parameters": { … } } ], "MaxLoopCount": 100, "BreakOnErrors": 3, "DelayMs": 1000 }}| Parameter | Default | Meaning |
|---|---|---|
Items |
– | What to iterate, see above |
Do |
– | Actions per iteration |
MaxLoopCount |
all | At most this many iterations |
BreakOnErrors |
unlimited | Stop after this many failed iterations; the loop then ends as failed |
DelayMs |
– | Pause after each iteration in milliseconds |
| Placeholder in the iteration | Content |
|---|---|
{{item}} |
the current element (always an object) |
{{item.value}} |
the value for simple elements |
{{index}} |
position, starting at 0 |
{{count}} |
number of all elements |
The result of an action in Do is stored under its name and overwritten in every iteration; after the loop it holds the last iteration. Nested loops share item, index and count: inside the inner loop they refer to its element, after the inner loop again to the outer one’s. Two loops running at the same time in two branches of a Parallel each have their own item.
Result
Section titled “Result”"Response": { "Results": [ { … result of every action of every iteration … } ], "ExecutedCount": 12, "ErrorCount": 0, "StopReason": "Completed"}StopReason is Completed, BreakOnErrors or StopWorkflow (a StopWorkflow action in Do ended the loop and the run).
If an action in Do fails, the remaining actions of that iteration are skipped, and the error is recorded with the element’s number in Status.Errors and ErrorCount. The loop continues with the next element until BreakOnErrors is reached. A run with errors in single iterations shows red in the workflow list.
Example
Section titled “Example”customers.csv:
Name;Email;CustomerNoMuster GmbH;info@muster.de;1001Beispiel AG;post@beispiel.de;1002{ "Type": "Loop", "Name": "WriteEachCustomer", "Parameters": { "Items": "C:\\RUNOS\\Data\\customers.csv", "DelayMs": 1000, "BreakOnErrors": 3, "Do": [ { "Type": "SMTP", "Name": "Write", "Parameters": { "SmtpServer": "smtp.example.com", "SmtpUser": "{{connector.Mailserver.Username}}", "SmtpPassword": "{{connector.Mailserver.Password}}", "From": "service@example.com", "To": "{{item.Email}}", "Subject": "Your customer number {{item.CustomerNo}}", "Body": "Hello {{item.Name}},\n\nyour customer number is {{item.CustomerNo}}." } } ] }}