- 23 May 2023
-
DarkLight
-
PDF
shift (array)
- Updated on 23 May 2023
-
DarkLight
-
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 isjob
andarr
, respectively. As an option, you can toggle the Run Window slider to set the arrayShift task to run on a schedule. -
The following displays the array variables that were set prior to running the workflow.
-
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.
-
The Outgoing tab displays the result of executing the
arrayShift
task. Notice that "Device 1" was removed from the beginning of the array.
Example 2
In this IAP example:
-
The job variables and incoming
arr
variable are empty. -
The output returns an empty array.