Array Manipulation
Middle's parameter system affords you the flexibility to create the automations you need
Last updated
Middle's parameter system affords you the flexibility to create the automations you need
Last updated
An array is a data structure that stores a list of elements, typically of the same type, where each element is accessible by an index. Middle is able to accommodate arrays within synced data and Action inputs and outputs.
An example of an array is a list of line items in an invoice. This list of line items would appear as an array, along with other fields in the invoice, such as the invoice ID and sale date.
When arrays are involved in your data you will need to use array manipulation parameters to parse out the data you need. Array manipulation tools can be used together to perform multiple functions to an array.
The count array manipulation allows you to count the elements in an array. In our invoice line item example, you'd count all the line items in that invoice. When using the count array parameter you will just need to select the array you'd like to count. You can compare the count against a number value.
Say you want to take all of an invoice's line items and derive a dollar value of the items purchased. This is when you'd use a reduce array. Whether you're reducing an array to a number value or text, you can use this manipulation to define a starting value (via the Accumulator Initial value) and then compile array data of your choosing (via the Reducer Operator) to end up with the value you need.
When calculating the Reducer Operator value, Middle will look at each object in the array and pass in the values you've selected. If you create a text or number parameter for the Reducer Operator, you can input a Reduce Special Variable Accumulator and then pair it with the Special Variable you'd like to reduce. The accumulator will keep track of the values grabbed from each object. In the case that you are adding up the price of each line item, the accumulator will keep a tally of the sum total of the line items, as each object is looked at.
In the Special Variable menu you will also see a Special Variable Index. This is number value of the object and its position in the array. For example, line item 1 would have a value of 0, line item 2 would have a value of 1, and so on.
Continuing our invoice line item example, say you want to get the value of line items that were only for certain products. You can use a Filter Array manipulation to set some criteria for which objects in an array will be counted or reduced. You will need to select the array you'd like to filter and then you can build the criteria you are filtering by. You will need to use Special Variables to reference the fields in the array objects.
Sometimes you need to take an array and may it to a new array. This is especially pertinent when pushing data to a bulk endpoint. When you set up a Map Array manipulation you'll have an option of what you want to map this array into. It could be anything from a complete object to pass to another system, to just a list of an individual field.
You are able to deduplicate an array when you've mapped an array to an individual field. For example, you could take your list of line items, map it into an array of product IDs, and then deduplicate the list so that you end up with a unique list of product IDs that were in the invoice. The Deduplicate Array tool currently cannot deduplicate across more than one field of data.