Simple loop actions

Completed

Use the Loop action when you need a predetermined number of repetitions. Another common use of simple loops is tasks where the loop index is important to the task itself. Let’s examine both cases with an example.

Consider the following flow: an Excel file contains employees’ names and email addresses. From those email addresses, employees send their business expenses - these email messages are retrieved, and each employee’s expenses are added to their respective row in the Excel file.

First, open the Excel report and determine the range of the data:

Screenshot of the workspace example.

When you select Excel, you need to specify the file or select a blank file as shown in the following image.

Screenshot of the excel loop.

Select the action under Excel called Get first free column/row from Excel workbook. This action produces variables that you can use in the Loop.

Screenshot of the Actions table with Get first free column highlighted.

Each of the rows, from 2 until the last populated row, contains the information of an employee (row 1 isn't included, because it contains headers). You need to both read and write to these rows, so you must use an index variable. Therefore, choose to use a loop action:

Screenshot of the Loop action properties.

Within the loop, set the sum of expenses to 0, read the employee’s email address, and retrieve the emails sent from their account to the designated one, with the subject line Company Expense:

Screenshot of the workspace loop parameters.

In this case inside the Loop, use the Read from Excel worksheet

From here use the Retrieve the Values of named cells and use the cell Name in the Name field.

Screenshot of Read Excel worksheet.

The next action you add is the Retrieve emails action as shown in the following image. You need to find your email IMAP information from your IT Department.

Screenshot of the Retrieve emails action properties dialog.

Finally, the email’s body, containing the expense amount, is written into the respective cell. Since only one email message is expected, use the body of the first (and only) email in the list of retrieved emails:

Screenshot of the completed workspace loop example.

Both reading the email address, and writing the expense amount (actions 5 and 7) require the use of the loop index variable. This variable ensures that each repetition of the loop accesses a different row in the Excel file.