请参阅 Application Integration 支持的连接器

合并两个 JSON 数组

使用“数据映射”任务,合并两个 JSON 数组,并将生成的输出存储在新的 JSON 变量中。

代码示例

{
    "triggerConfigs": [{
      "label": "API Trigger",
      "startTasks": [{
        "taskId": "1"
      }],
      "properties": {
        "Trigger name": "test_string_case_conversion_API_1"
      },
      "triggerType": "API",
      "triggerNumber": "1",
      "triggerId": "api_trigger/test_string_case_conversion_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\": \"$inputJsonArray1$\"\n        },\n        \"transformationFunctions\": [{\n          \"functionType\": {\n            \"jsonFunction\": {\n              \"functionName\": \"MERGE\"\n            }\n          },\n          \"parameters\": [{\n            \"initialValue\": {\n              \"referenceValue\": \"$inputJsonArray2$\"\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"
    }, {
      "key": "inputJsonArray1",
      "dataType": "JSON_VALUE",
      "defaultValue": {
        "jsonValue": "[{\n  \"name\": \"Abhishek\",\n  \"course\": \"Mechanical\"\n}, {\n  \"name\": \"Chirag\",\n  \"course\": \"Civil\"\n}, {\n  \"name\": \"Sachin\",\n  \"course\": \"Medical\"\n}, {\n  \"name\": \"Vivek\",\n  \"course\": \"Software\"\n}]"
      },
      "displayName": "inputJsonArray1",
      "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"name\": {\n        \"type\": \"string\"\n      },\n      \"course\": {\n        \"type\": \"string\"\n      }\n    }\n  }\n}"
    }, {
      "key": "inputJsonArray2",
      "dataType": "JSON_VALUE",
      "defaultValue": {
        "jsonValue": "[{\n  \"name\": \"Shubham\",\n  \"course\": \"IT\"\n}, {\n  \"name\": \"Dravid\",\n  \"course\": \"Mechanical\"\n}]"
      },
      "displayName": "inputJsonArray2",
      "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"name\": {\n        \"type\": \"string\"\n      },\n      \"course\": {\n        \"type\": \"string\"\n      }\n    }\n  }\n}"
    }],
    "userLabel": "v1"
  }

集成流程示例

下图显示了此集成代码示例的集成编辑器布局示例。

显示示例集成流程的图片 显示示例集成流程的图片

上传并运行示例集成

如需上传并运行示例集成,请按以下步骤操作:

  1. 集成示例保存为系统上的 .json 文件。
  2. 在 Google Cloud 控制台中,前往 Application Integration 页面。

    转到 Application Integration

  3. 在导航菜单中,点击集成。随即会出现集成列表页面。
  4. 选择现有集成,或通过点击创建集成来创建新的集成。

    要创建新的集成,请执行以下操作:

    1. 创建 Integrations对话框中输入名称和说明。
    2. 为集成选择一个区域。
    3. 为集成选择服务账号。您随时可以在集成工具栏的 集成摘要窗格中更改或更新集成的服务账号详细信息。
    4. 点击创建

    这将在集成编辑器中打开集成。

  5. 集成编辑器中,点击 “上传/下载”菜单,然后选择上传集成
  6. 在文件浏览器对话框中,选择您在第 1 步中保存的文件,然后点击 Open

    系统会使用上传的文件创建新版本的集成。

  7. 在集成编辑器中,点击测试
  8. 点击测试集成。这将运行集成,并在 Test Integration 窗格中显示执行结果。