Example: Using the ‘Each Item’ Loop
Suppose, you want fetch a list of all of your Trello cards and create a task in Google Tasks for each card. In this case, instead of creating separate workflows to fetch a single Trello card, and then creating a task in Google Tasks for the card, use the Each Item loop.
For this example, you need to perform the following steps:
The workflow is as shown in the following figure:
Step 1: Add actions to the canvas and create the workflow
1. Drag the Loop action to the canvas.
2. Drag the
Create New Task action under
Google Tasks onto the
Loop block. This action is automatically connected to
.
3. Connect the
Create New Task action to
.
4. Drag the Get List Cards action under Trello to the canvas.
5. Connect
to
Get List Cards,
Get List Cards to
, and
to
.
Step 2: Configure the Get List Cards action
The following steps provide details of the values that you need to specify in the action form for this specific example. For detailed steps on configuring this action, see
Get List Cards.
1. In your Trello account, do the following:
a. Create a board, Feature Lists.
b. In this board, add a list, Release 1.
c. Add 5 cards to the list, Decide Feature, Develop Feature, Test Feature, Document Feature, and Release Feature.
d. Add a description to each of the cards, Decision Card, Development Card, Testing Card, Documentation Card, and Release Card.
2. In ThingWorx Flow, in the Get List Cards action form, in the Board ID list, select Feature Lists.
3. In the List ID list, select Release 1.
Step 3: Configure the Loop action
The following steps provide details of the values that you need to specify in the action form for this specific example. For detailed steps on configuring this action, see
Loop.
1. In the Select Loop Type list, select Each Item.
2. In the Source Array or Object field, map the value of the Cards array of the Get List Cards action.
Step 4: Configure the Create New Task action
The following steps provide details of the values that you need to specify in the action form for this specific example. For detailed steps on configuring this action, see
Create New Task.
1. In your Google Tasks account, create a task list, Release Task List.
2. In ThingWorx Flow, in the Get List Cards action form, in the Task List ID list, select Release Task List.
3. In the
Title field, click
to add the following inline expression:
function result(){
var x = $a0.currentIndex
return $a1.cards[x].name
}
result()
, where a0 is the action ID of Loop, and a1 is the action ID of Get List Cards.
4. Click Show additional fields.
5. In the
Notes field, click
to add the following inline expression:
function result(){
var y = $a0.currentIndex
return $a1.cards[y].desc
}
result()
, where a0 is the action ID of Loop, and a1 is the action ID of Get List Cards.
Step 5: Execute the workflow
Click Save to save the workflow, and then click Execute to run the workflow.
When the workflow is being executed, the current iteration number and the total number of iterations is displayed above the Loop block, as shown in the following figure:
The output in the Debug Panel provides the following details of the Loop execution:
When iteration 1 of the Create New Task action executes, Decide Feature task with Decision Card description is created, in iteration 2, Develop Feature task with Development Card description is created, in iteration 3, Test Feature task with Testing Card description is created, in iteration 4, Document Feature task with Documentation Card description is created, and in iteration 5, Release Feature task with Release Card description is created.