object.iterator action

This trigger action receives an object and iterates over its key-value pairs.  Every time it is routed to, it will output the next key-value pair. 

Action

To access the object.iterator trigger action:

  • In the Adding trigger screen, under Object click and drag the object.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 key-value pairs have been iterated.

The right routing point (blue) is the next route. This route will be taken when each key-value pair gets iterated.

Form

Parameters

Name
Type
Required
Descriptions
Input Object Yes The object containing the key-value pairs.

Action variables

Name
Type
Description
$(action.X.key) String The key of the key-value pair.
$(action.X.value) ANY The value of the key-value pair that is currently being iterated.

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

Object iterator Sample

The Object iterator is defined so that it is possible to iterate through a list of objects and perform additional actions with the values of each object. The following example shows a dynamic event with an object iterator that generates attributes (key, value pairs). In this example, the attributes are added to a thing that is considered. The object iterator iterates through each object and generates the attributes.

To build the Object iterator sample, do the following:

  1. In the Trigger screen, click New Trigger button.
  2. Enter the Name of the trigger. For example, Object 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 object_iterator_example

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

  8. Click and hold while you drag object.iterator onto the canvas.
  9. Set the Input to be $(event.input)  
  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.attr.set action onto the canvas.
  14. Enter the following values:
    • The Thing key of the thing (thing_obj_iterator_test)to which you want to add the attributes.
    • Set the Attribute key to $(action.0.key)
    • Set the Value to $(action.0.value)
       
  15. Create the next Route to thing.attr.set  
  16. Create the success Route from thing.attr.set to 0.Object.iterator
  17.  Create the success Route from 0.Object.iterator to 0.Success.
The following API Request will trigger the above trigger event.
{
    "1": {
        "command": "trigger.dynamic.exec",
        "params": {
            "encoding": "object",
            "input": {
                "Name": "Telit",
                "Volume": 100,
                "Capacity": 1000
            },
            "key": "object_iterator_example"
        }
    }
}

The Attributes gets updated with the following attributes: