ApplicationExperienceEdge 1.0.0

Array Node

The Array Node allows a workflow to perform operations against an array on the payload.

Array Node

Node Properties

Array Source

The Source Array Path is the location on the payload at which the node will look for an array. If there is not an array at the given payload path, an empty one will be created at that path. If the given payload path is a string, the string will be treated as an array of characters for the array operation, but will remain a string on the payload.

If the operation modifies the original array, you can specify a destination path where the altered array will be stored.

Array Node Configuration

Operation

Once you have configured the array that the node will operate on, then you can choose and configure one of the following operations to perform.

Compact

The compact operation takes no arguments, and will remove all falsey values from the provided array. The values false, null, 0, undefined, NaN and 0-length strings are falsey.

Concat

The concat operation is used to combine the elements of two arrays. It takes one templatable argument: the array to be concatenated to the input array specified above at “Source Array Path”. Note: For edge workflows, this operation is only available on edge version 1.2.3 or higher.

Flatten

The flatten operation takes no arguments and will recursively flatten the provided array. This means that an array like [1, [2, [3], 4], [5]] will become the array [1, 2, 3, 4, 5].

Group By

Groups objects in an object array by a given value path. The Group By operation takes two arguments. The first is the value path, which is the path in the array objects around which to group the objects. For example, if you have an object array containing information about devices following the format { "name": "Device 1", "tags": { "zip": [ "45202" ] } }, you could group objects by name or tags.zip.[0]. The second is an output path, which is the payload path at which to store the grouped objects. If an object in the array does not have a value at the given path it will be grouped under undefined. Note: For edge workflows, the Group By operation is only available on edge version 1.18.1 or higher.

Index Of

The index of operation takes two arguments. The first is a templatable value to search for in the array. The second is a payload path, for the result of that search. If the value is found, the index of the first instance of that value in the array will be placed at that path, otherwise -1 will be placed there.

Insert At

The insert at operation is used to insert an item at a spot in the array, and it takes two arguments. The first is a templatable value to insert into the array. The second is a templatable array index. Negative numbers are acceptable, and will operate from the end of the array instead of the beginning.

Length

The length operation calculates the length of the array. It takes one argument, a payload path where the length of the array will be placed.

Lookup At

The lookup at operation is used to lookup the element at a particular index in the array. It takes two arguments, the first of which is a templatable array index. Negative numbers are acceptable, and will operate from the end of the array instead of the beginning. The second argument is a payload path where the element at that index will be placed. If the index is outside the bounds of the array, the element will be undefined.

Pop

The pop operation is used to pull off the last element in the array. It takes one (optional) argument, a payload path where that element should be placed. If the array has no items, the element will be undefined.

Push

The push operation is used to add an element to the end of the array. It takes one argument, a templatable value which will be the element to append.

Remove At

The remove at operation is used to remove am item at a particular index in the array. It takes two arguments, the first of which is a templatable array index. Negative numbers are acceptable, and will operate from the end of the array instead of the beginning. The second argument is optional, and is a payload path where the removed element will be placed. If the index was not within the bounds of the array, the removed element will be undefined.

Replace At

The replace at operation is used to replace an element at a particular index in the array. It takes three arguments, the first of which is a templatable value that will be used as the replacement element. The second is a templatable array index. Negative numbers are acceptable, and will operate from the end of the array instead of the beginning. The third argument is optional, and is a payload path where the replaced element will be placed. If the index was not within the bounds of the array, the replaced element will be undefined (but the replacement element.will still be added to the array at that index).

Reverse

The reverse operation reverses the order of all elements in the array.

Shift

The shift operation is used to pull off the first element in the array. It takes one (optional) argument, a payload path where that element should be placed. If the array has no items, the element will be undefined.

Sum

The sum operation is used to find the sum of all numeric elements in the array. If an array element is non-numeric it will not be counted in the total. It takes one argument, a payload path at which the sum should be placed. Note: For edge workflows, the Group By operation is only available on edge version 1.18.1 or higher.

Unshift

The unshift operation is used to add an element to the beginning of the array. It takes one argument, a templatable value which will be the element to prepend.

Node Example

Given an array of the following objects, an operation of “Group By” and a value path of tags.zip.[0]:

[
  { "name": "Device 1", "tags": { "zip": [ "45202" ] } },
  { "name": "Device 2", "tags": { "zip": [ "45202" ] } },
  { "name": "Device 3", "tags": { "zip": [ "45101" ] } },
  { "name": "Device 4", "tags": { "zip": [ "45101" ] } },
  { "name": "Device 5", "tags": { "zip": [ "45300" ] } },
]

The Array Node places the following at the specified output path:

{
  "45202": [ { "name": "Device 1", "tags": { "zip": [ "45202" ] } },  
            { "name": "Device 2", "tags": { "zip": [ "45202" ] } } ],
  "45101": [ { "name": "Device 3", "tags": { "zip": [ "45101" ] } },
          { "name": "Device 4", "tags": { "zip": [ "45101" ] } } ],
  "45300": [ { "name": "Device 5", "tags": { "zip": [ "45300" ] } } ]
}

If the original array is at working.devices and the destination array is working.grouped the resulting payload might look like this:

{
  "applicationName": "1234",
  "flowName": "groups",
  "flowId": "5f1215425824150006020376",
  "relayType": "user",
  "relayId": "5eda4db1f5f37d00072001c8",
  "flowVersion": "develop",
  "triggerType": "virtualButton",
  "triggerId": "5f1215425824150006020376-n0pCJERi8xyciOsfvrqTt",
  "applicationId": "5ede6a9b4e9e6d0006466b49",
  "working": {
    "devices": [
      { "tags": { "zip": [ "45202" ] }, "name": "Device 1" },
      { "tags": { "zip": [ "45202" ] }, "name": "Device 2" },
      { "tags": { "zip": [ "45101" ] }, "name": "Device 3" },
      { "tags": { "zip": [ "45101" ] }, "name": "Device 4" },
      { "tags": { "zip": [ "45300" ] }, "name": "Device 5" }
    ]
  },
    "grouped": {
    "45101": [
      { "tags": { "zip": [ "45101" ] }, "name": "Device 3" },
      { "tags": { "zip": [ "45101" ] }, "name": "Device 4" }
    ],
    "45202": [
      { "tags": { "zip": [ "45202" ] }, "name": "Device 1" },
      { "tags": { "zip": [ "45202" ] }, "name": "Device 2" }
    ],
    "45300": [
      { "tags": { "zip": [ "45300" ] }, "name": "Device 5" }
    ]
  },
  "time": "2020-07-22T13:42:07.263Z"
}

Node Errors

In most cases, invalid data in an array is handled by setting the return value to undefined. In the case that a required field is missing or contains an invalid value, an error halts the current workflow.