Loop

The 'Loop' action lets you run an action or a set of actions in a loop. When you drag this action to the canvas, it looks like a block within which you can add multiple actions and create a mini-workflow. You can then connect this loop action to other actions of your workflow. When you execute the workflow, Built.io Flow executes this mini-workflow repeatedly till it reaches the specified count.

To use ‘Loop’ in your workflow, add this action to your canvas and expand this block so you can add multiple actions within it. From the list of actions on the right, add actions as per your requirements into this block, and connect all the actions within it as you would normally do for a workflow. 

To configure loop settings, click on the ‘Settings’ icon that appear when you hover on this Loop block. There are two types of loop settings that you can choose from: Times and Each Item

Times lets you do a particular thing x number of times. Each Item lets you perform a certain action for all the elements of a collection. 

Let’s look at each of these options individually. 


Times

Times loop allows you to perform a certain action ‘x’ number of times. It lets you specify the number of times the loop block should be executed. It is recommended that you run this loop when the workflow within 'Loop' action doesn't need its input from the previous action.

Field data

Number of Times (Mandatory): Enter the number of times you wish to execute the loop. 

Let’s understand this with an example. Suppose you need to create five new notes in Evernote with same content. Instead of adding same action five times, we can use 'Times' loop. To do this, follow the instructions given below:

Step 1:  Add the 'Loop' action in your canvas, and add 'Evernote_Create Note' into the 'Loop' block and connect them as shown below:

2-loop.png

Step 2: Configure the 'Evernote_Create Note' action as per the instructions given below:

Authorize Evernote: Select the appropriate authorization from the drop-down list. If you haven't created an authorization yet, click on 'Add new' to create one. 

Title: Provide a suitable title for the note you wish to create. 

Notebook ID: Select/specify the ID of the notebook in which you wish to create a new note. You can also search the notebook by its name or ID.

Body (Optional): Enter the content that you wish to add in the note.

1-evernote-config.png


Once you have entered all the details, click on 'Next'. You will be redirected to the ‘Test Action’ window where you can see the input data provided by you to configure the 'Evernote - New Note’ action along with a ‘Test’ button.

3-test-evernote.png

When you click on the ‘Test’ button, Built.io Flow will actually perform the action. It will automatically create a new note in your Evernote account and will show the output of this action in the window that appears. This output can then be used to configure the rest of the workflow. once you have entered all the details, click on 'Done'. This will take you back to the canvas. 

Step 3: Next, configure the 'Loop' action as shown below:

Select loop type: Since we need to run the loop for specific number of times, select 'Times'.

Number of Times: Enter the number of times (5) you wish to execute the loop. 

3_loop_times.png

Once you have entered all the details, click on 'Done' and 'Run' the workflow. This will run the loop within the Loop action five times, and will create five identical notes in your Evernote account.


Each Item

Each Item is used to loop through each key/value pair in the given array. It traverses the given array list, i.e., it goes through each element of the given array. Hence, this action accepts arrays or objects received from previous actions as input. You need not specify the number of times it should run. This loop will be executed multiple times, each time taking one item or object of the array as specified in the ‘Array or Object’ field. 

Field data

Source Array or Object (Mandatory): Enter the array or object over which you wish the loop to iterate, from the previous action.

Let's learn more about 'Each Item' with an example. 

The ‘Get Tasks from Wunderlist’ action returns the list of all tasks of a list. It returns an array that conains tasks as objects. Each object contains properties such as id, title, type, creation date, etc. of a task. 

Let’s say you wish to retrieve just the title of all tasks, instead of all the details. Each Item lets you do this. Let’s see how this can be done. 

Step 1: Add 'Get tasks from Wunderlist', 'Loop' and 'Logger' action to your canvas and connect them as shown below:

4_flow.png

Step 2: Configure 'Get tasks from Wunderlist' action as shown below:

Authorize Wunderlist: Select the appropriate authorization from the drop-down list. If you haven't created an authorization yet, click on 'Add new' to create one.

List ID: Select/specify the ID of the list of which you wish to retrieve the tasks.

4-wunderlist-config.png

Once you have entered all the details, click on 'Next'. You will be redirected to the ‘Test Action’ window where you can see the input data provided by you to configure the 'Wunderlist - Get Tasks From a List’ action along with a ‘Test’ button.

5-wunderlist-test.png

When you click on ‘Test’, Built.io Flow will automatically fetch the latest list from your Wunderlist account and display the tasks added in the list. This data will be used as sample data to configure the rest of the workflow.Once you have entered all the details, click on 'Done'. This will take you back to canvas.

Step 3: Next, configure 'Loop' action as shown below:

Select Loop: Since we need to retrieve all the items of the list, select 'Each Item' loop.

Array or object: Add the output array of 'Wunderlist' action given on the right hand side of the configuration window, as an input for this field.

6-loop.png

Click on the ‘Next’ button. You will be redirected to the ‘Test Action’ window where you can see the input data provided by you to configure the ‘Loop’ action along with a ‘Test’ button.

7-loop-test.png

When you click on ‘Test’, Built.io Flow will automatically iterate over each array element and display its details. This data will be used as sample data to configure the rest of the workflow. Once you have entered all the details, click on 'Done'. This will take you back to canvas.

Step 4: Add 'Logger' action to the canvas and configure it as shown below:

Log: Add the output parameter '{{$a1currentValue}}' of the 'Loop' action given on the right hand side of the configuration window, as an input for this field. This parameter returns all the values of all the key/value pairs of the specified array/object. 

Now, since we need only title from the details of every array item, append '.title' to the input field value. So the input value for the log field should be '{{$a1.currentValue.title}}'.

8-loop-title-output.png

You can also retrieve values for multiple properties, by clicking on '+ADD' link. Once you have entered all the details, click on 'Next'. You will be redirected to the ‘Test Action’ window where you can see the input data provided by you to configure the ‘Logger’ action along with a ‘Test’ button.

9-logger-test.png

When you click on the ‘Test’ button, Built.io Flow will actually perform the action. It will automatically fetch the title of the first task and will show the output of this action in the window that appears. This output can then be used to configure the rest of the workflow. Once you have tested the action, click on 'Done' and 'Run' the workflow.

This will return the task titles from a specified list of your 'Wunderlist' account.

Output:
  • output-arrow loop-128 Loop
    • left-triangle index number
    • left-triangle length number
    • left-triangle key string
    • left-triangle value any
    • left-triangle continue boolean