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:
- In the Trigger screen, click
New Trigger button.
- Enter the Name of the
trigger. For example, Object iterator
example
- Right-click on the Start node to display the trigger event window.
- Click on the Event type drop-down and select the dynamic
- Set key to
object_iterator_example
- Click the Add button.
- Expand the Object
actions
- Click and hold while you
drag object.iterator onto
the canvas.
- Set the Input to be $(event.input)
- Click the Add button
- Create the Route from
the dynamic event to
the 0.object.iterator
- Expand the Thing
actions
- Click and hold while you
drag thing.attr.set action onto
the canvas.
- 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)
- Create the next Route to thing.attr.set
- Create the
success Route from thing.attr.set
to 0.Object.iterator
- Create the
success Route from 0.Object.iterator to 0.Success.
{
"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: