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.
Input and output properties are shown below.
||Array||Required. The array to shift.|
||Array||The shifted array.|
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
arr, 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 Job Manager.
The Outgoing tab displays the result of executing the
arrayShifttask. Notice that "Device 1" was removed from the beginning of the array.
In this IAP example:
The job variables and incoming
arrvariable are empty.
The output returns an empty array.
For general information on how to use tasks in Automation Builder, refer to the Tasks section in the Automation Studio documentation.