Each Item
Each Item is used to iterate 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 Objectfield.
To use this loop, select Each Item in the Select Loop Type drop-down field and array/object you want to iterate through in the Number of Times field.
Let’s understand how to use this loop type with the help of an example.
The Trello - Get All List Cards action returns the list of all cards of a list. It returns an array that contains cards as objects. Each object contains properties such as id, title, type, and creation date associated with each card.
Let’s say you want to retrieve just the title of all cards, instead of all the details and send it to a specific recipient. The Each Item loop type allows you do this.
Follow the instructions given below to achieve this:
-
Add Trello connector and Loop action to canvas and connect them.
-
Double-click the Trello icon, select the Get All List Cards action from the Select action drop down list, and select the Trello account you want to use to execute the action. Once this is done, click Next. In the action configuration form that appears next, provide the details as given below:
Board ID: Select/specify the ID of the board of which cards you want to retrieve.
List ID: Select/specify the ID of the list of which cards you want to retrieve.
-
Once you have entered all the details, click Next. You will be redirected to the Test Action window where you need to Test the action to check if you have configured it properly, and click on Done to return to canvas.
-
Next, hover on the Loop action icon, click the Settings icon that appear, and configure the Loop action.
Select Loop type: Since we need to retrieve all the items of the list, select Each Item Loop type.
Source Array or object: Add the Cards array listed under the Trello - Get All List Cards action given on the left-side of the configuration window, as an input for this field.
Once you have entered all the details, click Next, optionally Test the Loop action, and click Done. This will take you back to loop canvas. Next, double-click the Loop action icon. This will take you to the loop canvas. Add Send an Email action between Loop Start and Loop Stop icons. This will take you back to the workflow canvas.
- Configure the Send an Email action as given below:
To: Enter the email ID of the person you want to send the list of cards to. Subject: Provide a suitable subject for the email. As the Loop action will be iterating through all elements of the array, we will use the output keys of the Loop action in the Body. Body: Locate the currentItem key listed under the loop output on the left-side of the screen. This key contains all the details of the element currently under execution. As we want only the name of the card, click on the drop down icon and locate the name key. Add this key in the Body field. This will fetch the name of the array element currently under execution.
-
Once you have entered all the details, click Next, Test the Loop action, and click Done. This will take you back to loop canvas.
-
Click on the Close Loop Canvas icon (X) located at the top-right corner of the loop canvas. This will take you back to the workflow canvas.
-
Save the workflow and click Test to start workflow execution.This will fetch all card details from the specified Trello list, fetch the name of each card using loop, and send it to the specified recipient via email.