Looping
Looping allows you to perform the same actions repeatedly and only stops after it loops all the items.
Looping is helpful when you want to process multiple similar items, for example filling forms where the value is from a Google Sheets. There are several ways to do looping in Automa:
- Use the Loop Data block to loop through a variable, table, google sheets or custom JSON Array.
- Use the Loop Elements block to loop through elements on the page.
- Use the Repeat Task block for repeatedly doing actions a specified number of times.
Using the Loop Data or Loop Elements Block
When using the Loop Data or Loop Elements block, the Loop Breakpoint must include in the workflow. The Loop Breakpoint is for telling the workflow where the scope of the loop is. And inside the Loop Breakpoint, you also must input the Loop id of the loop block.
The above workflow will repeatedly execute the Forms and the Get Text block based on the numbers of the items. And after it loops all the items, the workflow will continue to the Export Data block.
And when you're not defining the loop scope using the Loop Breakpoint block, the looping will not work.
The above will execute the Forms and the Get Text block once and then continue to the Export Data block.
Access Loop Item
You can use expressions to access data from the current loop iteration inside the loop scope. For example, {{loopData.loopId}}
; replace the loopId
with the Loop id you inputted inside the Loop Data or Loop Element block.
The {{loopData.loopId}}
expression will return:
{
"data": ...,
"$index": 1
}
So if you want to access the index of the loop, you can use expressions like {{loopData.loopId.$index}}
; And to get the loop value, you don't need to write the data
property like {{loopData.loopId.data}}
; Automa will automatically assign it to the expressions. But if you use JavaScript expressions, you must include the data
property !!{{loopData.loopId.data}}
Using the Repeat Task Block
Using the Repeat Task block is the easiest way to do looping. You only need to define how many times to repeat the actions and where to start to repeat them.
The above will start to repeat to execute from the Click Element block, and after it executes three times. The workflow will continue to the New Tab block.