Skip to main content

Collection Tools Component

Common collection operations

Component key: collection-tools

Description#

Actions#

Aggregate#

Apply aggregate function to list | key: aggregate

InputDefaultNotesExample
Input
Aggregate Function
string
Default
Notes
Aggregate function to apply
Example
sum
Input
Filter Function
code
Default
(value, index) => { return true; }
Notes
Filter out any elements that do not return true
Example
(value) => value.someProperty === 17
Input
List
data
/ Required
Default
Notes
Reference to a list of data to operate on
Example
 

Output Example Payload#

{  "data": 117}

Append#

Append element to the end of the list | key: append

InputNotes
Input
Element
data
/ Required
Notes
Reference to an element to look for
Input
List
data
/ Required
Notes
Reference to a list of data to operate on

Output Example Payload#

{  "data": [    1,    2,    3,    4  ]}

Chunks#

Chunk the list into lists of the specified number of elements | key: chunks

InputDefaultNotes
Input
List
data
/ Required
Default
Notes
Reference to a list of data to operate on
Input
Number of Elements
string
/ Required
Default
1
Notes
Number of Elements to take

Output Example Payload#

{  "data": [    [      1,      2,      3    ],    [      4,      5,      6    ],    [      7,      8,      9    ]  ]}

Combine Collection#

Combine multiple collections into a single object. | key: combineCollections

InputNotesExample
Input
Collections
string
/ Required
Key Value List
Notes
Returns an object with the specified key and corresponding collection as the value
Example
[ {"key": "CustomerQueryResult", "value": { Customer: { Name: "Acme Contracting" } }}, {"key": "AccountQueryResult", "value": { Account: { AccountId: "123123123" } }}, ]

Output Example Payload#

{  "data": {    "CustomerQueryResult": {      "Customer": {        "Name": "Acme Contracting"      }    },    "AccountQueryResult": {      "Account": {        "AccountId": "123123123"      }    }  }}

Concatenate#

Concatenate two lists together into a single list | key: concatenate

InputNotes
Input
List
data
/ Required
Notes
Reference to a list of data to operate on
Input
List
data
/ Required
Notes
Reference to a list of data to operate on

Output Example Payload#

{  "data": [    1,    2,    3,    4,    5,    6  ]}

Count#

Count the number of occurrences of element in list | key: count

InputNotes
Input
Element
data
/ Required
Notes
Reference to an element to look for
Input
List
data
/ Required
Notes
Reference to a list of data to operate on

Output Example Payload#

{  "data": 3}

Create Object#

Creates a new object from provided key/value pairs | key: createObject

InputNotes
Input
Key & Value Pairs
data
/ Required
Key Value List
Notes
Key and value pairs

Output Example Payload#

{  "data": {    "first": "value",    "second": 17  }}

De-duplicate#

De-duplicate the elements of the list | key: deduplicate

InputNotes
Input
List
data
/ Required
Notes
Reference to a list of data to operate on

Output Example Payload#

{  "data": [    1,    2,    3  ]}

Field Value Mapping#

Maps the values from two different collections and returns a key/value list where the 'key' is the value of the Key Mappings input and the 'value' is the value of the Value Mappings input | key: fieldValueMapping

InputNotesExample
Input
Key Mappings
data
Notes
 
Example
[{"key":"AccountName","value":"Deploy_Time_Specified_Account_Name__c"},{"key":"AccountValue","value":"Deploy_Time_Specified_Account_Value__c"}]
Input
Value Mappings
string
Key Value List
Notes
 
Example
[{"key":"AccountName","value":"bar"},{"key":"AccountValue","value":"baz"}]

Output Example Payload#

{  "data": [    {      "key": "Deploy_Time_Specified_Account_Name__c",      "value": "bar"    },    {      "key": "Deploy_Time_Specified_Account_Value__c",      "value": "baz"    }  ]}

Filter#

Filter elements of a list | key: filter

InputDefaultNotesExample
Input
Filter Function
code
Default
(value, index) => { return true; }
Notes
Filter out any elements that do not return true
Example
(value) => value.someProperty === 17
Input
List
data
/ Required
Default
Notes
Reference to a list of data to operate on
Example
 

First#

Get first element from a list | key: first

InputNotes
Input
List
data
/ Required
Notes
Reference to a list of data to operate on

Last#

Get last element from a list | key: last

InputNotes
Input
List
data
/ Required
Notes
Reference to a list of data to operate on

Length#

Count the number of elements in list | key: length

InputNotes
Input
List
data
/ Required
Notes
Reference to a list of data to operate on

Output Example Payload#

{  "data": 7}

Map#

Transform a list and its elements | key: map

InputDefaultNotesExample
Input
Context Data
data
Default
Notes
Additional contextual data to supply to the Transform Function
Example
 
Input
Filter Function
code
Default
(value, index) => { return true; }
Notes
Filter out any elements that do not return true
Example
(value) => value.someProperty === 17
Input
List
data
/ Required
Default
Notes
Reference to a list of data to operate on
Example
 
Input
Transform Function
code
Default
(value, index) => { return value; }
Notes
Function to transform each element
Example
(value) => value.someProperty

Process In Order#

Ensures that payloads are processed in order across executions according to an ordering specified by a payload attribute. Returns the largest possible set of ordered payloads on the Process branch, and otherwise follows the Skip branch and returns the current item. | key: processInOrder

InputNotesExample
Input
Collection ID
string
/ Required
Notes
A value that uniquely identifies the collection that is being processed out of order.
Example
da41e39f-ea4d-435a-b922-c6aae3915ebe
Input
Collection Length
data
/ Required
Notes
The number of items in the collection. When processing is finished the interim data for the collection is removed.
Example
100
Input
Item
data
/ Required
Notes
The current item to consider for processing.
Example
{ Index: 0, Name: "Acme Contracting" }
Input
Item Index
data
/ Required
Notes
The integer value to consider as the index for the current item that specifies intended processing order. 0 is the first index value.
Example
10

The Process In Order action allows you to send several requests to an instance out of order, and helps to ensure that data runs through your integration in order. Requests with data payloads are collected, and when an ordered set of requests have been received this action processes the requests in the order you specify.

In order to use this action, you will need to know how many total items you are sending ahead of time.

Example: suppose we are updating an inventory system with three updates, and order is important. We want to process widgets first, then gadgets, and finally whatsits. We know that we have three items to import, and due to limitations of our third-party system we can't send them all at once. We're not confident that they'll arrive to Prismatic in any particular order, so we'll use this action to help.

Collection Tools - Process in Order flow in Prismatic integration designer

We'll come up with a unique "Collection ID", and begin sending our data in any order:

$ curl 'https://hooks.prismatic.io/trigger/EXAMPLE==' \    --header "Content-Type: application/json" \    --data '{"item": "whatsits", "index": 2}' \    --header 'collectionid: abc-123' \    --header 'collectionlength: 3'
$ curl 'https://hooks.prismatic.io/trigger/EXAMPLE==' \    --header "Content-Type: application/json" \    --data '{"item": "widgets", "index": 0}' \    --header 'collectionid: abc-123' \    --header 'collectionlength: 3'
$ curl 'https://hooks.prismatic.io/trigger/EXAMPLE==' \    --header "Content-Type: application/json" \    --data '{"item": "gadgets", "index": 1}' \    --header 'collectionid: abc-123' \    --header 'collectionlength: 3'

The first time that our integration is invoked, the {"item": "whatsits", "index": 2} payload will be stored for future processing, since items with index 0 and 1 have not yet been processed.

The second time that our integration is invoked, the {"item": "widgets", "index": 0} payload will be processed immediately, since it has index 0, but then our loop will stop since an item with index 1 has not yet been received.

The third time our integration is invoked, the {"item": "gadgets", "index": 1} will be processed right away, since it has index 1 and an item with index 0 has already been processed. The {"item": "whatsits", "index": 2} payload will also be pulled from storage and processed since it is next in line to be processed.

At this point all items will have been processed.

Note: Items must be zero-indexed.

Output Example Payload#

{  "data": [    {      "Index": 0,      "Name": "Acme Contracting"    },    {      "Index": 1,      "Name": "FooBar Consulting"    }  ],  "instanceState": {    "7d577253-3ef0-4a0a-bb7f-8335c2596e70": {      "da41e39f-ea4d-435a-b922-c6aae3915ebe": {        "lastIndex": 1,        "items": []      }    }  },  "branch": "Process"}

Remove#

Remove all occurrences of an element from a list | key: remove

InputNotes
Input
Element
data
/ Required
Notes
Reference to an element to look for
Input
List
data
/ Required
Notes
Reference to a list of data to operate on

Output Example Payload#

{  "data": [    1,    3  ]}

Take First#

Take first number of elements from a list | key: takeFirst

InputDefaultNotes
Input
List
data
/ Required
Default
Notes
Reference to a list of data to operate on
Input
Number of Elements
string
/ Required
Default
1
Notes
Number of Elements to take

Output Example Payload#

{  "data": [    1,    2,    3  ]}

Take Last#

Take last number of elements from a list | key: takeLast

InputDefaultNotes
Input
List
data
/ Required
Default
Notes
Reference to a list of data to operate on
Input
Number of Elements
string
/ Required
Default
1
Notes
Number of Elements to take

Output Example Payload#

{  "data": [    7,    8,    9  ]}