Nested Loop
You can also create loop within loop (nested loop) to build complex workflows. There is no limit on the number of loops you can add.
Let's understand how to configure a nested loop with the help of an example.
Let's say you want to create a workflow which fetches all cards from a specific Trello board, creates a new note for each card in a specific notebook in Evernote, and post the details of the note on a specific space in Cisco Webex Teams.
To do this, we will use two levels of loop. The steps given below explain the steps to do this:
- Create main workflow Drag-and-drop Trello - Get Board Cards action on canvas and configure it as you would normally do. Next, add the Loop action to canvas, connect it with Trello - Get Board Cards action, and configure it.
- Hover over the Loop action icon and click the Settings icon. This will open the Loop action configuration window. Set Select Loop Type field to Each Item and add Cards key listed in the output of the Trello - Get Board Cards action in the Source Array/Object field, like we did in the previous example. Once this is done, click Next, optionally Test the action and click Done. This will take you back to canvas. You can now start adding other actions inside the loop.
- To add actions to Loop, double click the Loop icon. You will see a Loop canvas within the original canvas. This is where you can add actions you want to execute inside the Loop. As we want to create a note for each Trello card in Evernote, add the Evernote - Create Note and Loop actions to canvas and connect them to Loop Start and Loop Stop icons.
- Add the name key listed under the Loop - currentItem key in the Title key and desc key in the
Body key. Specify the notebook in which you want to create notes in the Notebook ID field.
Once this is done, click Next, optionally Test the action, and click Done. This will take you back to Loop canvas. Next, hover over the Loop action icon and click the Settings icon. This will open the Loop configuration window. Set the Select Loop Type to Times and enter 1 in the Number of Times field.
Once this is done, click Next, optionally Test the action, and click Done. This will take you back to Loop canvas.
- To add actions to Loop - Level 2, double-click the Loop action. This will open the Loop-Level 2
canvas.
By clicking the relevant breadcrumbs link highlighted in the image above, you can toggle between different loop levels. You can now add actions to this Loop - Level 2 canvas, just like we did in the previous step.
For the purpose of our example, we want to post the details of the created note on a specific Cisco Webex Teams space. To do so, add the Cisco Webex Teams - Post New Message action on canvas and add it to Loop Start and Loop Stop icons.
Configure the Cisco Webex Teams - Post New Message action. Specify the space on which you want to post the message in the Space ID field. Add the title and content keys listed under the Evernote - Create Note action in the Message field.
-
Once this is done, click Next, optionally Test the action, and click Done. This will take you back to Loop - Level 2 canvas. With this, your workflow is complete. Click on the Close icon (X) located at the upper-right corner of the Loop - Level 2 canvas. This will take you back to the main workflow. Save the workflow and run it. This will fetch all cards from the specified list in Trello, create a note for each card in Evernote, and post the details of the note on the specified Cisco Webex Teams space.
This was just an example of how you can use nested loop. You can add more loops levels and create complex workflows as per your requirements.