push

The push task adds an element to the end of an array. It dynamically appends the array upon which it is invoked and returns the new array.

Potential use case

For an upcoming network fiber rollout, you need to sort through multiple contact records to collect email addresses of customers in a specific area code so you can notify them of enhanced service availability. As these customers are found in the database, use the push task to add their email addresses to an array that a downstream email task can then loop through for sending notifications.

Properties

IncomingTypeDescription
arrArrayRequired. The target array to receive the pushed element.
elementNAnyRequired. The element to push.
OutgoingTypeDescription
pushedArrayArrayThe array with the pushed element appended.

Example 1

In the example below, the reference task selected for each incoming variable is job.

push task with arr and elementN mapped to job variables

The reference variable for each incoming variable is arr and elementN, respectively. You can optionally toggle the Run Window slider to set the task to run on a schedule.

The array variables are set prior to running the workflow.

Job variable setup showing the arr and elementN values before running

If the array is empty, an error is returned in the output.

Error returned when the arr value is an empty array

After running the workflow, the variable names and incoming variables appear under the Incoming tab in Task History (accessed from Jobs in Operations Manager).

Incoming tab showing the variable names and values passed to the task

The Outgoing tab shows the result. Notice that “Device 3” was added to the end of the array.

Outgoing tab showing Device 3 appended to the end of the array

Example 2

In this example, a new array is created within the workflow and a single value is pushed into it.

  • The arr value is statically set as [].
  • The elementN value is statically set as the string "Lemon".
  • The outgoing pushedArray variable contains one item: ["Lemon"].
push task creating a new array and pushing a single Lemon element

Example 3

In this example, a new array is created with a space value already in it, then the elementN value is pushed immediately into it.

  • The arr value is statically set as [" "].
  • The elementN value is statically set as the string "Lemon".
  • The outgoing pushedArray variable contains two items: [" ","Lemon"].
push task showing a space element followed by Lemon in the resulting array