# Repeat for each loop

A Repeat for each loop executes actions inside a block of steps for each item in a given list. The actions you select to repeat must use data output from the Repeat for each loop's datatree to ensure that every item in the list is processed. Actions nested under a Repeat for each block are carried out for all items in the list.

For example, a Repeat for each block allows you to create a loop that processes each item in a list of invoice line items.

Repeat for each is a type of Repeat control statement.

To insert a Repeat for each loop into a recipe, click the + (plus) button in the recipe editor to add a new step and select Repeat for each.

Select Repeat for each Select Repeat for each

Workato adds a block of steps to the recipe where you can configure the app and action to take for each item in a list.

Repeat for each block Repeat for each block

# Example: Repeat for each loop

The following example demonstrates how to use the Repeat for each loop to sync Salesforce accounts using the batch trigger to Zendesk as organizations.

Repeat for each loop example scenario Use the Repeat for each loop to iterate through a list of Salesforce accounts. Example recipe (opens new window)

In this example, the trigger returns a list of Salesforce accounts. Since Zendesk does not support batch actions, each Salesforce account must be added one at a time from Salesforce to Zendesk.

The list datapill must be passed into the Repeat for each block. When the input list field is selected, only list type datapills are usable in the datatree, as shown in the following image. List datapills can be identified through their stack icon.

Map list data pill into the Repeat for each block Mapping a list data pill into the Repeat for each block's input list field. Example recipe (opens new window)

Datapills from the Repeat for each output datatree must be mapped to ensure that values from each list item are used when the action is repeated. For example, if the trigger fetches two Salesforce accounts, using datapills from the Repeat for each datatree ensures that the Create organization action creates a Zendesk organization with the data from the first Salesforce account on its first iteration, then with the data from the second Salesforce account on its second iteration.

Use datapills from the Repeat for each block Use datapills from the Repeat for each block's datatree. This ensures values from the list being iterated through are used. Example recipe (opens new window)

The following image displays the mapping from the Repeat for each datatree.

Repeat for each step example Datapills are mapped from the Repeat for step's datatree. Example recipe (opens new window)

For further Repeat for each loop examples and more information about list processing, refer to the list management (opens new window) documentation.

# Repeat for each in batches


Occasionally, the rate at which an upstream app or system transmits the data is faster than the rate at which a downstream app or system can receive it. You can use the Repeat for each in batches feature to process data by configuring the batch size. Large data sets are automatically parsed into smaller batches for transfer. Each item in the data set is only processed once.

For example, you can use the Repeat for each in batches feature to create a batch of Salesforce leads from a list of leads in a CSV.

# How to use

To use the Repeat for each in batches feature:

1

Log in to your Workato account and navigate to Projects.

2

Click the Create button and select Recipe to create a new recipe or click an existing recipe and select Edit recipe.

3

Click the + (plus) button to add a new step.

4

Select Repeat for each.

Select Repeat for each Select Repeat for each

Workato adds a block of steps to the recipe and automatically selects the Set up list to repeat steps for each item step.

Set up list to repeat steps for each item in the Repeat for each block Set up list to repeat steps for each item in the Repeat for each block

5

Enter an input list datapill in the Input list field.

Input list Input list

6

Select Batch of items from the Repeat mode drop-down menu.

Repeat mode drop-down menu Repeat mode drop-down menu

7

Set the Batch size field. This defaults to 100 when the batch size is not specified or if the number specified is less than 1. Note that a datapill can also be entered as a batch size.

Set batch size Set batch size

8

You can see this reflected in the For each statement with the Batch tag.

Repeat for each loop batch size Repeat for each loop batch size

Refer to an example recipe (opens new window) for more information.


Last updated: 1/25/2024, 9:16:44 PM