shift (array)
  • Dark
    Light
  • PDF

shift (array)

  • Dark
    Light
  • PDF

shift (array) Task Purpose

The shift (array) task is used to remove the first element from an array and return the original array minus the removed element. This task also changes the length of the array by shortening the array by one element and moving everything down. If the array is empty, then the output returns an empty array. Of note, pop (array) has similar behavior to shift (array), but is applied to the last element in an array.

Potential Use Case

Your company is gathering "time to repair" statistics from a database. The statistics are stored in an array with the largest result as the first array element, and the smallest result as the last array element. Company policy dictates that you discard the largest and least result values when considering the average. You could employ the shift (array) task to remove the largest value from the array, and then apply pop (array) to that result to remove the smallest value from the array. With clean array values, subsequent tasks in your automation can then calculate the average time to repair.

Properties

Input and output properties are shown below.

Incoming Type Description
arr Array Required. The array to shift.


Outgoing Type Description
shiftedArray Array The shifted array.

Example 1

In the IAP examples shown below:

  • For this task, the incoming property variable (arr) is required. The reference task (used to define the data source) and reference variable is job and arr, respectively. As an option, you can toggle the Run Window slider to set the arrayShift task to run on a schedule.

    shiftArray-01

  • The following displays the array variables that were set prior to running the workflow.

    shiftArray-02

  • Once the workflow is executed, the incoming variables are displayed under the Incoming tab in Task History, which is accessed from Jobs in Operations Manager.

    shiftArray-03

  • The Outgoing tab displays the result of executing the arrayShift task. Notice that "Device 1" was removed from the beginning of the array.

    shiftArray-04

Example 2

In this IAP example:

  • The job variables and incoming arr variable are empty.

    shiftArray-05

    shiftArray-06

  • The output returns an empty array.

    shiftArray-07


What's Next