更新指定索引的 JSON 陣列

使用資料對應工作,透過輸入變數更新指定索引處的 JSON 陣列值。將輸出內容儲存在新的 JSON 變數中。

程式碼範例

{
  "triggerConfigs": [{
    "label": "API Trigger",
    "startTasks": [{
      "taskId": "1"
    }],
    "properties": {
      "Trigger name": "tkApplicationIntegrationSample1_API_1"
    },
    "triggerType": "API",
    "triggerNumber": "1",
    "triggerId": "api_trigger/tkApplicationIntegrationSample1_API_1"
  }],
  "taskConfigs": [{
    "task": "FieldMappingTask",
    "taskId": "1",
    "parameters": {
      "FieldMappingConfigTaskParameterKey": {
        "key": "FieldMappingConfigTaskParameterKey",
        "value": {
          "jsonValue": "{\n  \"@type\": \"type.googleapis.com/enterprise.crm.eventbus.proto.FieldMappingConfig\",\n  \"mappedFields\": [{\n    \"inputField\": {\n      \"fieldType\": \"JSON_VALUE\",\n      \"transformExpression\": {\n        \"initialValue\": {\n          \"referenceValue\": \"$jsonArray$\"\n        },\n        \"transformationFunctions\": [{\n          \"functionType\": {\n            \"jsonFunction\": {\n              \"functionName\": \"TO_STRING_ARRAY\"\n            }\n          }\n        }, {\n          \"functionType\": {\n            \"stringArrayFunction\": {\n              \"functionName\": \"SET\"\n            }\n          },\n          \"parameters\": [{\n            \"initialValue\": {\n              \"literalValue\": {\n                \"intValue\": \"2\"\n              }\n            }\n          }, {\n            \"initialValue\": {\n              \"referenceValue\": \"$jsonVar$\"\n            },\n            \"transformationFunctions\": [{\n              \"functionType\": {\n                \"jsonFunction\": {\n                  \"functionName\": \"TO_STRING\"\n                }\n              }\n            }]\n          }]\n        }, {\n          \"functionType\": {\n            \"stringArrayFunction\": {\n              \"functionName\": \"TO_JSON\"\n            }\n          }\n        }]\n      }\n    },\n    \"outputField\": {\n      \"referenceKey\": \"$outputJsonArray$\",\n      \"fieldType\": \"JSON_VALUE\",\n      \"cardinality\": \"OPTIONAL\"\n    }\n  }]\n}"
        }
      }
    },
    "taskExecutionStrategy": "WHEN_ALL_SUCCEED",
    "displayName": "Data Mapping"
  }],
  "integrationParameters": [{
    "key": "outputJsonArray",
    "dataType": "JSON_VALUE",
    "displayName": "outputJsonArray",
    "inputOutputType": "OUT",
    "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"prop1\": {\n        \"type\": \"string\"\n      }\n    }\n  }\n}"
  }, {
    "key": "jsonArray",
    "dataType": "JSON_VALUE",
    "defaultValue": {
      "jsonValue": "[{\n  \"prop1\": \"val11\"\n}, {\n  \"prop1\": \"val21\"\n}, {\n  \"prop1\": \"val31\"\n}, {\n  \"prop1\": \"val41\"\n}]"
    },
    "displayName": "jsonArray",
    "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"prop1\": {\n        \"type\": \"string\"\n      }\n    }\n  }\n}"
  }, {
    "key": "jsonVar",
    "dataType": "JSON_VALUE",
    "defaultValue": {
      "jsonValue": "{\n  \"prop1\": \"valUserDefined\"\n}"
    },
    "displayName": "jsonVar",
    "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"prop1\": {\n      \"type\": \"string\"\n    }\n  }\n}"
  }]
}

整合流程範例

下圖顯示這個整合程式碼範例的整合編輯器版面配置範例。

顯示範例整合流程的圖片 顯示範例整合流程的圖片

上傳並執行範例整合

如要上傳並執行範例整合,請按照下列步驟操作:

  1. 將整合範例儲存為系統上的 .json 檔案。
  2. 在 Google Cloud 控制台中,前往「Application Integration」頁面。

    前往 Application Integration

  3. 按一下左側導覽選單中的「Integrations」(整合),開啟「Integrations」(整合) 頁面。
  4. 選取現有整合項目,或按一下「建立整合項目」來建立新的整合項目。

    如要建立新的整合:

    1. 在「Create Integration」(建立整合) 對話方塊中,輸入名稱和說明。
    2. 選取整合作業的區域。
    3. 選取整合作業的服務帳戶。您隨時可以透過整合工具列中的「Integration summary」(整合摘要) 窗格,變更或更新整合項目的服務帳戶詳細資料。
    4. 點選「建立」。

    系統會在整合編輯器中開啟整合。

  5. 在整合編輯器中,按一下「Upload/download menu」圖示 ,然後選取「Upload integration」。
  6. 在檔案瀏覽器對話方塊中,選取您在步驟 1 儲存的檔案,然後按一下「Open」。

    系統會使用上傳的檔案建立新的整合版本。

  7. 在整合編輯器中,按一下「Test」(測試)。
  8. 按一下「測試整合」。系統會執行整合,並在「Test Integration」(測試整合) 窗格中顯示執行結果。