Use case: pass collections dynamically using custom actions passing-collection
You can pass a collection in custom action parameters that will be dynamically populated at runtime. Two kinds of collections are supported:
-
simple collections: arrays of simple data types, for example, with a listString:
code language-none { "deviceTypes": [ "android", "ios" ] }
-
object collections: an array of JSON objects, for example:
code language-none { "products":[ { "id":"productA", "name":"A", "price":20.1 }, { "id":"productB", "name":"B", "price":10.0 }, { "id":"productC", "name":"C", "price":5.99 } ] }
Limitations limitations
-
Nested arrays of objects within an object array are not supported at the moment. For example:
code language-none { "products":[ { "id":"productA", "name":"A", "price":20, "locations": [{"name": "Paris"}, {"name": "London"}] }, ] }
-
To test collections using the test mode, you need to use the code view mode. Code view mode is not supported for business events at the moment. You can only send a collection with a single element.
General procedure general-procedure
In this section, we will use the following JSON payload example. This is an array of objects with a field that is a simple collection.
{
"ctxt": {
"products": [
{
"id": "productA",
"name": "A",
"price": 20.1,
"color":"blue",
"locations": [
"Paris",
"London"
]
},
{
"id": "productB",
"name": "B",
"price": 10.99
}
]
}
}
You can see that “products” is an array of two objects. You need to have at least one object.
-
Create your custom action. See this page.
-
In the Action parameters section, paste the JSON example. The displayed structure is static: when pasting the payload, all fields are defined as constants.
-
If needed, adjust the field types. The following field types are supported for collections: listString, listInteger, listDecimal, listBoolean, listDateTime, listDateTimeOnly, listDateOnly, listObject
note note NOTE The field type is automatically inferred according to the payload example. -
If you want to pass objects dynamically, you need to set them as variables. In this example we set “products” as variable. All the object fields included in the object are set to variables automatically.
note note NOTE The first object of the payload example is used to define the fields. -
For each field, define the label which will be displayed in the journey canvas.
-
Create your journey and add the custom action you created. See this page.
-
In the Action parameters section, define the array parameter (“products” in our example) using the advanced expression editor.
-
For each of the following object field, type the corresponding field name from the source XDM schema. If the names are identical, this is not needed. In our example, we only need to define “product id” and “color”.
For the array field, you can also use the advanced expression editor to perform data manipulation. In the following example, we use the filter and intersect functions:
Particular cases examples
For heterogeneous types and arrays of arrays, the array is defined with the listAny type. You can only map individual items, but cannot change the array to variable.
Example of heterogenous type:
{
"data_mixed-types": [
"test",
"test2",
null,
0
]
}
Example of array of arrays:
{
"data_multiple-arrays": [
[
"test",
"test1",
"test2"
]
]
}
Related topics