Pass collections dynamically using custom actions

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

  • 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

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.

  1. Create your custom action. See this page.

  2. In the Action parameters section, paste the JSON example. The displayed structure is static: when pasting the payload, all fields are defined as constants.

  3. 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.
  4. 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.
  5. For each field, define the label which will be displayed in the journey canvas.

  6. Create your journey and add the custom action you created. See this page.

  7. In the Action parameters section, define the array parameter (“products” in our example) using the advanced expression editor.

  8. 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

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

Use custom actions

recommendation-more-help
4f4a00c1-77c9-4eee-84df-bbe6206c3ab9