Create conditionals and loops

Completed

As mentioned before, actions within a flow are run sequentially. However, there are certain actions that can alter this sequence, to achieve greater flexibility and adaptability while running a flow.

In this unit, we examine two main categories of such actions: Conditionals and Loops.

Conditionals

Conditional actions allow flows to modify their behavior during runtime, based on the data available at the time. Essentially, they allow flows to make choices based on the information at their disposal.

In the previous example, we can add a Conditional action to modify the flow's behavior based on the contents of the first cell.

We add an If action to the workspace, configuring it as below:

Screenshot of the If action properties dialog.

We want to check whether the variable that contains the data we read from the worksheet in the previous action contains the desired header.

Note

Selecting the variable icon next to the input field will produce a list of available variables to add to the field; this makes variables easier to handle. Screenshot of the variable icon and variable list.

Press Save to add the action to the workspace. An End action is also automatically added, to signify the end of the conditional block of actions; any actions added between the If and End actions only run if the condition in the If action is met.

We add a Write to Excel worksheet action to test this. If the header isn't correct, we would like to write it in:

Screenshot of the Write to Excel worksheet action properties dialog.

Screenshot of the actions workspace with the If action added.

Loops

Loops enable flow to repeat a block of actions multiple times. The type of loop action used and its configuration determines the number of repetitions.

Let’s expand the current example by adding Row IDs up to row 10; to achieve this, we use the Loop action.

The Loop action initializes an index variable, and repeats until said variable reaches a specified value. The index variable increments by a certain value with each repetition:

Note

To pass a static numeric value add a leading equals to the number value. Example: =10

Screenshot of the Loop action properties dialog.

Configured as above, the variable =LoopIndex initializes to 2, and increments by 1 each time the loop repeats, until it reaches the value 10.

When we add the Loop action, an End action is also automatically added to the workspace; this is analogous to the End action in the previous unit.

Between the Loop and End actions, we add a Write to Excel worksheet action, which writes the ID in each row:

Note

Add 1 to the LoopIndex on Row to skip over the column header.

Screenshot of the Write to Excel worksheet action properties dialog with parameters filled in.

Screenshot of the actions workspace with the Loop added.

In this case, the loop index is used to both determine the row in which the flow writes, and the contents to be written. When this loop runs, all rows from 2 to 11 contain the numbers 1-10 in column A.