Automation Action: For Each
Create a loop on various properties and execute Actions inside the loop.
Allows you to create a loop based on the following:
- Message Recipients (All, To, CC or BCC)
- Message Attachments (Regular Attachments, Inline Attachments only or both)
- Message Keywords
- Message Headers
- Extracted Fields
- List values contained in a List (See: List Operation)
- Lines contained in any variable
- Comma Separated Values contained in any variable
- Email addresses, URL's and Tokens contained in any variable
- Data Reader Rows (See: Open Database Reader)
- Json Member in
- Variable Value
Inside the loop you can assign the values of the current loop item and current iteration count to variables. You can then use these values in actions within the loop.
For example, when looping on Recipients you can assign the Email Address & Name of the current recipient in the loop to variables by selecting from the Assign To drop downs.
When looping on Lines the Lines In will be split into lines (based on carriage returns and/or line feeds). Each non-blank line will then assigned to the loop value.
When looping on Comma Separated Values In, the In value will be split on commas. Quoted values will be handled. For example, if Comma Separated Values In contained:
1997,Ford,E350,"Super, luxurious truck"
.. then the loop would be executed 4 times with values:
- Super, luxurious truck
When looping on Json Member In the In value can be assigned any Json text. The loop will execute for each member. The Start At Path can be optionally set to a Json path (using dot notation). You can assign each member Name and Value to variables. See: Looping Through Json Member Values Using For..Each
When looping on Tokens the Tokens In value will be split into words and tokens.
When looping on Keywords the incoming message body will be split into unique words (excluding common words).
When looping on a Variable Value - this assumes the variable is numeric. The loop executes n times - where n is the variable value.
You then place actions to execute inside the For Each - Next Loop block.
You can exit a loop using the Exit Loop action. This can be placed in an If block if you need to exit a loop based on a condition. Processing will continue with the action following the Next Loop action.
The Continue Loop action moves processing to the Next Loop action. The loop will continue with the next iteration of the loop - or exit the loop if there are no more iterations. You can place the Continue Loop action in an If block if you need to move to the next iteration based on a condition.