Application Integration でサポートされているコネクタをご覧ください。

JSON 配列内の値をフィルタする

データ マッピング タスクを使用して、ブール値基準に基づいて JSON 配列の要素をフィルタし、フィルタした出力を新しい JSON 変数に格納します。

コードサンプル

{
  "triggerConfigs": [{
    "label": "API Trigger",
    "startTasks": [{
      "taskId": "1"
    }],
    "properties": {
      "Trigger name": "filter_orders_greater_than500_API_1"
    },
    "triggerType": "API",
    "triggerNumber": "1",
    "triggerId": "api_trigger/filter_orders_greater_than500_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\": \"$orders.orderLines$\"\n        },\n        \"transformationFunctions\": [{\n          \"functionType\": {\n            \"jsonFunction\": {\n              \"functionName\": \"FILTER_ELEMENTS\"\n            }\n          },\n          \"parameters\": [{\n            \"initialValue\": {\n              \"literalValue\": {\n                \"protoValue\": {\n                  \"@type\": \"type.googleapis.com/enterprise.crm.eventbus.proto.TransformExpression\",\n                  \"initialValue\": {\n                    \"referenceValue\": \"~x\"\n                  },\n                  \"transformationFunctions\": [{\n                    \"functionType\": {\n                      \"jsonFunction\": {\n                        \"functionName\": \"GET_PROPERTY\"\n                      }\n                    },\n                    \"parameters\": [{\n                      \"initialValue\": {\n                        \"literalValue\": {\n                          \"stringValue\": \"qty\"\n                        }\n                      }\n                    }]\n                  }, {\n                    \"functionType\": {\n                      \"jsonFunction\": {\n                        \"functionName\": \"TO_INT\"\n                      }\n                    }\n                  }, {\n                    \"functionType\": {\n                      \"intFunction\": {\n                        \"functionName\": \"GREATER_THAN\"\n                      }\n                    },\n                    \"parameters\": [{\n                      \"initialValue\": {\n                        \"literalValue\": {\n                          \"intValue\": \"500\"\n                        }\n                      }\n                    }]\n                  }]\n                }\n              }\n            }\n          }]\n        }]\n      }\n    },\n    \"outputField\": {\n      \"referenceKey\": \"$flag_orders$\",\n      \"fieldType\": \"JSON_VALUE\",\n      \"cardinality\": \"OPTIONAL\"\n    }\n  }]\n}"
        }
      }
    },
    "taskExecutionStrategy": "WHEN_ALL_SUCCEED",
    "displayName": "Data Mapping"
  }],
  "integrationParameters": [{
    "key": "orders",
    "dataType": "JSON_VALUE",
    "defaultValue": {
      "jsonValue": "{\n  \"orderLines\": [{\n    \"lineNumber\": 1.0,\n    \"productNumber\": 123.0,\n    \"unitPrice\": 1.0,\n    \"qty\": 1.0,\n    \"taxAmount\": 1.0\n  }, {\n    \"lineNumber\": 2.0,\n    \"productNumber\": 321.0,\n    \"unitPrice\": 10.0,\n    \"qty\": 5.0,\n    \"taxAmount\": 10.0\n  }, {\n    \"lineNumber\": 3.0,\n    \"productNumber\": 456.0,\n    \"unitPrice\": 10.0,\n    \"qty\": 1000.0,\n    \"taxAmount\": 10.0\n  }]\n}"
    },
    "displayName": "orders",
    "inputOutputType": "IN",
    "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"orderLines\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"unitPrice\": {\n            \"type\": \"number\"\n          },\n          \"qty\": {\n            \"type\": \"number\"\n          },\n          \"productNumber\": {\n            \"type\": \"number\"\n          },\n          \"lineNumber\": {\n            \"type\": \"number\"\n          },\n          \"taxAmount\": {\n            \"type\": \"number\"\n          }\n        }\n      }\n    }\n  }\n}"
  }, {
    "key": "flag_orders",
    "dataType": "JSON_VALUE",
    "displayName": "flag_orders",
    "inputOutputType": "OUT",
    "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"unitPrice\": {\n        \"type\": \"number\"\n      },\n      \"qty\": {\n        \"type\": \"number\"\n      },\n      \"productNumber\": {\n        \"type\": \"number\"\n      },\n      \"lineNumber\": {\n        \"type\": \"number\"\n      },\n      \"taxAmount\": {\n        \"type\": \"number\"\n      }\n    }\n  }\n}"
  }]
}

統合フローのサンプル

次の図は、この統合コードサンプルの統合エディタのサンプル レイアウトを示しています。

統合フローのサンプルを示す画像 統合フローのサンプルを示す画像

サンプル統合をアップロードして実行する

サンプル統合をアップロードして実行するには、次の手順に従います。

  1. 統合サンプルを .json ファイルとしてシステムに保存します。
  2. Google Cloud コンソールで [Application Integration] ページに移動します。

    Application Integration に移動

  3. ナビゲーション メニューで [統合] をクリックします。[統合リスト] ページが表示されます。
  4. 既存の統合を選択するか、[統合を作成] をクリックして新しい統合を作成します。

    新しい統合を作成する場合:

    1. [統合の作成] ダイアログで名前と説明を入力します。
    2. 統合のリージョンを選択します。
    3. 統合用のサービス アカウントを選択します。統合のサービス アカウントの詳細は、統合ツールバーの [統合の概要] ペインでいつでも変更または更新できます。
    4. [作成] をクリックします。

    統合エディタで統合が開きます。

  5. 統合エディタで、 [アップロード / ダウンロード メニュー] をクリックし、[統合をアップロード] を選択します。
  6. ファイル ブラウザ ダイアログで、ステップ 1 で保存したファイルを選択し、[開く] をクリックします。

    統合の新しいバージョンは、アップロードされたファイルを使用して作成されます。

  7. 統合エディタで [テスト] をクリックします。
  8. [テスト統合] をクリックします。統合が実行され、[テスト統合] ペインに実行結果が表示されます。