Working with loops in RPAs

This article explains how to add loops to processes in process maps, allowing for repetitive actions based on conditions.

Help CentreBuilding Processes

Once you understand Working with Process maps, you can add conditions to processes. Although a loop is simply a matter of creating a circular process, with a condition to determine the end of the loop, you need to be mindful of how it is used in RPA.

A loop works the same as a condition, in that every time it loops over this "loop" activity, a condition is checked. To better understand how conditions work, please read Working with conditions.


1. Add a loop

Once on a process map:

  1. Navigate to the process where you would like to add a loop
  2. Click on the green button’s drop-down (right side of the green button labelled “Process”)
  3. On the menu that appears, click on the + Activity item. The activity form opens:
    {{popups:rpas/add}}
  4. From here you can give the Loop a name, and select the “Loop” activity from the “Actions” menu: {{popups:rpas/add:action=loop}}
  5. This will prompt you to select the type of loop you want, e.g., “For each cell in Excel” and you can define some conditions if you want to
  6. Click "Add" once you are done

Another way to insert a loop in your process is to copy another activity and then edit it. Read Working with Process maps to understand how to edit a process activity.


2. Types of loops

We currently support the following types of loops:


2.1 For each row in an Excel sheet

This means that the bot will run the loop, for each row in an Excel sheet. When selecting this option, you will need to specify the Excel document File Path, as well as the Sheet Name, and the first data cell (the top left cell of your data table). There is also a toggle to indicate to the bot if the data contains a header row. We recommend that you make use of data sets with header rows, as these can be specified and used as variables throughout the rest of the process. There is also a section where you can add Optional Filters. This is useful if you have a data set but would only like to run the loop for a column that contains a specific value. E.g. Say you have a column with the heading “Names” and in it you have various names, but you only want the bot to run for rows that contain “An" (for Hannah, Samantha, Anna, Morgan) you would add a filter where; Column: {Name}, Operator: Contains, Value: An.


2.2 For each file in a folder

The bot will iterate over each file found in a specific folder. When selecting this option, you will need to specify the folder path. You can then also add Optional Filters, to allow it to run only for new excel documents. You do this by adding a filter where; Column: {extension}, Operator: =, Value: .xlsx. Alternative filters that will achieve the same are:

  • {path} endswith xlsx
If in subsequent process steps you need to specify the file path, you can use the variable {path} as this will vary throughout the loop. Read Working with variables in RPAs to understand which variables you may use.


2.3 For each folder in a folder

The bot will iterate over each sun-folder found in a specific folder. The same principles apply as for the “Each file in a folder” option.


2.4 For each record from a JSON file

The bot will iterate over each record found in a JSON file.


2.5 For each record from an API

The bot will iterate over each record found after calling an API.


2.6 For each record from a list

The bot will iterate over each record found in a list (in memory). To point to the variable in memory, i.e. for each line item in an invoice, assuming the invoice was stored under the variable "invoice", the variable will be "invoice::line items", and can be stored in the "Counter variable" i.e. "line-item".  To then access each line item within the loop, you can simply use "{line-item::before tax}". Also read the article

Working with invoices.

2.7 For each row from a website table

The bot will iterate over each record / row found in a website's table.


2.8 For each unread email

The bot will iterate over each unread email found in an inbox.


2.9 Number of times

Here you can specify the number of times that the bot should loop through the process. This is handy if the process will always need to loop for a specified number of times.


2.10 For each sheet in an Excel workbook

The bot will iterate over each worksheet (tab) in an Excel workbook, rather than the rows of a single sheet. This is useful when a workbook holds many sheets that all need the same processing.


2.11 While a condition is true

The bot keeps repeating the loop for as long as a condition you specify stays TRUE, and stops as soon as it becomes FALSE. Use this when you don't know up front how many times to loop – for example "while there are more pages to load".

Warning: Make sure the loop's condition will eventually become FALSE – otherwise the loop runs forever.

3. Connect the loop to the process

Once you have added the "Loop" activity / RPA to the process, it might not be in the correct position on the process map, or it may not be connected to the correct activities. You can drag this loop activity to where it should be in the process, and then connect it to the appropriate activities. For more on how to do this, read Working with Process maps.

Note that there should be at least one connection coming into the loop activity, and at least two connections "exiting" or going out the loop activity / RPA. Of these two, one should be set to “Default/True” and the other to “False”. The “Default/True” connection should lead to the steps that you want to loop for, and the “False” connector should lead to the activity / process step that needs to happen once the all the loops has been completed.


4. Set the connection labels

Once the loop is created and in the correct position within the process, it is important to indicate which activities will follow next. You can set these by clicking on a connection, and changing the type, if:

  1. The loop condition is met (TRUE): Leading to the steps that you want to loop for.
  2. The loop condition is not met (FALSE): Leading to the steps that needs to happen once all the loops are done.

It is important to note that a loop activity can’t have more than one connection of the same type coming from / out of it.

See it working on your own data

Everything documented here ships with the platform – try the document tools free, or go live in 7 days.