將集合傳遞至自訂動作參數 passing-collection

在此頁面上:​瞭解如何將簡單和物件集合傳遞至自訂動作引數,以便在執行階段動態填入。

您可以在自訂動作引數中傳遞集合,這些引數會在執行階段以動態方式填入。

支援兩種型別的集合:

  • 簡單集合

    將簡單集合用於基本值清單,例如字串、數字或布林值。 當您只需要傳遞專案清單而沒有其他屬性時,這些會很有用。

    例如,裝置型別清單:

    code language-json
    {
     "deviceTypes": [
         "android",
         "ios"
     ]
    }
    
  • 物件集合

    當每個專案包含多個欄位或屬性時,使用物件集合。 這些通常用於傳遞結構化資料,例如產品詳細資訊、事件記錄或專案屬性。

    例如:

    code language-json
    {
    "products":[
       {
          "id":"productA",
          "name":"A",
          "price":20.1
       },
       {
          "id":"productB",
          "name":"B",
          "price":10.0
       },
       {
          "id":"productC",
          "name":"C",
          "price":5.99
       }
     ]
    }
    
NOTE
集合中的巢狀陣列僅部分支援自訂動作請求承載。 如需詳細資訊,請參閱限制

一般程式 general-procedure

在本節中,我們會使用下列JSON裝載範例。 這是一個物件陣列,其中的欄位是一個簡單的集合。

{
  "ctxt": {
    "products": [
      {
        "id": "productA",
        "name": "A",
        "price": 20.1,
        "color":"blue",
        "locations": [
          "Paris",
          "London"
        ]
      },
      {
        "id": "productB",
        "name": "B",
        "price": 10.99
      }
    ]
  }
}

您可以看到products是兩個物件的陣列。 您至少需要一個物件。

  1. 建立您的自訂動作。 請在此頁面了解更多。

  2. 在​ 動作引數 ​區段中,貼上JSON範例。 顯示的結構為靜態:貼上裝載時,所有欄位都會定義為常數。

    運算式編輯器,顯示集合函式和作業

  3. 如有需要,請調整欄位型別。 集合支援下列欄位型別:listString、listInteger、listDecimal、listBoolean、listDateTime、listDateTimeOnly、listDateOnly、listObject

    note
    NOTE
    根據裝載範例自動推斷欄位型別。
  4. 如果您想要以動態方式傳遞物件,則需要將物件設定為變數。 在此範例中,我們將products設定為變數。 物件中包含的所有物件欄位都會自動設定為變數。

    note
    NOTE
    裝載範例的第一個物件用於定義欄位。
  5. 針對每個欄位,定義將顯示在歷程畫布中的標籤。

    篩選集合函式與條件產生器介面 {width="70%"}

  6. 建立您的歷程並新增您建立的自訂動作。 請在此頁面了解更多。

  7. 在​ 動作引數 ​區段中,使用進階運算式編輯器定義陣列引數(範例中為products)。

    包含欄位選取範圍的集合篩選運算式

  8. 對於以下每個物件欄位,輸入來源XDM結構描述中的對應欄位名稱。 如果名稱相同,則不需要這樣做。 在我們的範例中,我們只需要定義product id和"color"。

    具有排序組態的集合排序函式 {width="50%"}

針對陣列欄位,您也可以使用進階運算式編輯器來執行資料操作。 在下列範例中,我們使用篩選器交集函式:

使用篩選、排序和限製作業完成集合運算式

限制 limitations

雖然自訂動作中的集合可提供傳遞動態資料的靈活性,但需注意某些結構限制:

  • 支援自訂動作中的巢狀陣列

    Adobe Journey Optimizer支援自訂動作​ 回應承載 ​中的巢狀物件陣列,但此支援限於​請求承載

    在請求裝載中,只有當巢狀陣列包含固定數量的專案時(如自訂動作設定中所定義),才支援巢狀陣列。 例如,如果巢狀陣列一律包含剛好三個專案,則可將其設定為常數。 當專案數量需要為動態時,只能將非巢狀陣列(位於底層的陣列)定義為變數。

    範例:

    1. 下列範例說明​不支援的使用案例

      在此範例中,產品陣列包含具有動態專案數的巢狀陣列(locations),這在要求裝載中不受支援。

      code language-json
      {
      "products": [
         {
            "id": "productA",
            "name": "A",
            "price": 20,
            "locations": [
            { "name": "Paris" },
            { "name": "London" }
            ]
         }
      ]
      }
      
    2. 支援的範例,包含定義為常數的固定專案。

      在此情況下,巢狀位置會由固定欄位(location1location2)取代,讓裝載在支援的設定中保持有效。

      code language-json
      {
      "products": [
         {
            "id": "productA",
            "name": "A",
            "price": 20,
            "location1": { "name": "Paris" },
            "location2": { "name": "London" }
         }
      ]
      }
      
  • 測試集合:若要使用測試模式測試集合,您必須使用程式碼檢視模式。 請注意,商業事件不支援程式碼檢視模式,因此在這種情況下,您只能傳送包含單一元素的集合。

特定案例 examples

針對異質型別和陣列陣列,陣列是以listAny型別定義。 您只能對應個別專案,但無法將陣列變更為變數。

具有混合資料型別和欄位選擇的異質集合 {width="70%"}

異質型別範例:

{
    "data_mixed-types": [
        "test",
        "test2",
        null,
        0
    ]
}

陣列陣列範例:

{
    "data_multiple-arrays": [
        [
            "test",
            "test1",
            "test2"
        ]
    ]
}

其他資源

瀏覽以下章節,進一步瞭解設定、使用及疑難排解自訂動作的相關資訊:

AI Knowledge Reference

This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.

For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.

  • TL;DR: This page explains how to pass simple and object collections dynamically into custom action parameters in Journey Optimizer, including supported field types, the configuration procedure, and known limitations around nested arrays.

Intents:

  • Configure a custom action to accept a collection (simple or object) as a dynamic parameter
  • Define array parameters as variables in the advanced expression editor when building a journey
  • Apply filter and intersect functions to manipulate array data in the expression editor
  • Understand and work within the nested array limitations for custom action request payloads
  • Test collection parameters using code view mode in journey test mode

Glossary:

  • Simple collection: A list of basic scalar values (strings, numbers, booleans) passed as a custom action parameter (product-specific)
  • Object collection: A list of structured objects, each with multiple fields, passed as a custom action parameter (product-specific)
  • listObject: The field type used in custom action configuration to represent an array of objects (product-specific)
  • listAny: The field type used for heterogeneous arrays or arrays of arrays where items have mixed types (product-specific)
  • Variable (vs. Constant): In action parameter configuration, a field set to “variable” is populated dynamically at runtime from the journey context, while a “constant” is a fixed value set at configuration time (product-specific)

Guardrails:

  • Nested arrays in request payloads are only supported when they contain a fixed number of items (defined as constants); dynamic nested arrays are not supported
  • Code view mode is required to test collections in test mode; code view is not supported for business events, so only single-element collections can be sent in that case
  • At least one object must be present in the payload example used to define collection fields
  • The first object of the payload example defines the fields for the entire collection

Terminology:

  • Canonical name: Collection — Acronym: none — variants: array, list, dynamic collection
  • Synonyms: “simple collection” = “list of scalar values” ; “object collection” = “array of objects”
  • Do not confuse: “listAny” ≠ “listObject” (listAny handles heterogeneous or nested arrays; listObject handles uniform arrays of structured objects)

FAQ:

  • Q: What is the difference between a simple collection and an object collection? — A simple collection contains basic scalar values (strings, numbers, booleans), while an object collection contains structured objects each with multiple named fields.
  • Q: How do I make a collection parameter dynamic at runtime? — In the custom action’s Action parameters section, set the array field to “variable”; all object fields within it are then automatically set to variables.
  • Q: Are nested arrays supported in custom action request payloads? — Only partially. Nested arrays with a fixed, known number of items can be defined as constants. Nested arrays with a dynamic number of items are not supported in request payloads.
  • Q: How do I test a collection in journey test mode? — Use code view mode in the test interface. Note that business events do not support code view, so only single-element collections can be tested in that context.
  • Q: What field types are supported for collections? — listString, listInteger, listDecimal, listBoolean, listDateTime, listDateTimeOnly, listDateOnly, and listObject are all supported.
recommendation-more-help
journey-optimizer-help