array.iterator action

This trigger action receives an array of data and iterates over each element in the array from the first item to the last item.  Every time it is routed to, it will output the next element in the array. 

Action

To access the array.iterator trigger action:

  • In the Adding a trigger screen, under Array click and drag the array.iterator to the canvas.

Canvas

When dragged onto the canvas, the appearance of the action is a diamond with three routing points.

The left routing point (red) is the failure route. This route will be taken if the array to be evaluated results in an error.

The bottom routing point (gray) is the done route. This route will be taken when all the items in the array have been iterated.

The right routing point (blue) is the next route. This route will be taken when each item in the array gets iterated.

Form

Parameters

Name
Type
Required
Descriptions
Input Array Yes The array of items.

Action variables

Name
Type
Description
$(action.X.index) Integer The index of the element.
$(action.X.value) ANY The element of the array that is currently being iterated.

The following array iterator sample provides you an overview of using the array iterator with a step-by-step example:

Array iterator Sample

The Array iterator is defined so that it is possible to iterate through a list of items in an array and perform additional actions with the values of each array item. The following example shows a dynamic event with an array iterator that generates three tags. In this example, the tags are added to a thing that is considered. The array iterator iterates through each item and assigns a tag.

To build the Array iterator sample, do the following:

  1. In the Trigger screen, click New Trigger button.
  2. Enter the Name of the trigger. For example, Array iterator example
  3. Right-click on the Start node to display the trigger event window.  
  4. Click on the Event type drop-down and select the  dynamic  
  5. Set key to array_iterator_example

  6. Click the Add button.  
  7. Expand the Array actions

  8. Click and hold while you drag array.iterator onto the canvas.
  9. Set the Input to be $(event.input.my_array). my_array is the array that will contain the tags. In this instance, the my_array event input variable will contain three elements: [ "one", "two", "three" ]  
  10. Click the Add button  
  11. Create the Route from the dynamic event to the 0.object.iterator

  12. Expand the Thing actions
  13. Click and hold while you drag thing.tag.add to the canvas.
  14. Enter the Thing key of the thing (thing_array_iterator_test)to which you want to add the attributes.
  15. Create the next Route to thing.tag.add  
  16. Create the success Route from thing.tag.add to 0.array.iterator
  17.  Create the success Route from 0.array.iterator to 0.Success.
The following API Request will trigger the above trigger event.
{
    "1": {
        "command": "trigger.dynamic.exec",
        "params": {
            "encoding": "object",
            "input": {
                "my_array": [
                    "one",
                    "two",
                    "three"
                ]
            },
            "key": "array_iterator_example"
        }
    }
}

The following tags get added to the thing.