LoginSignup
0
0

Workato:ServiceNowのバッチAPIによるレコードの追加・更新手順

Last updated at Posted at 2024-04-22

はじめに

WorkatoでServiceNowのバッチAPI(以下)を利用する場合は、ServiceNowコネクタのCustom actionで対応することになります。

バッチAPIを利用すると、1アクションでServiceNowのレコード追加・更新の一括処理が可能なため、ServiceNowのパフォーマンス改善や、Workatoのタスク効率化等のメリットに繋がります。

ただし、Custom actionを利用するゆえに手順が複雑になり、実装の敷居も高くなります。以下では、ServiceNowのバッチAPIをによるレコード追加・更新手順について、順を追って詳細に説明を行います。

手順

image.png

Step 2

1.Variables by Workatoコネクタを追加します。

image.png

2.「Create variable」をクリックします。

image.png

3.「Add a variable」をクリックします。

image.png

4.「table」というフィールドを追加します。

image.png

5.「table」フィールドに、テーブル名をセットします。

image.png

Step 3

1.Variables by Workatoコネクタを追加します。

image.png

2.「Create list」をクリックします。

image.png

3.List nameに「records」と入力し、「add fields manually」をクリックします。

image.png

4.適当なフィールド名を入力し、「Add field」をクリックします。

このフィールドは、後で削除されます。

image.png

5.「Edit Schema」をクリックします。

image.png

6.エディタの内容をすべて削除し、以下の内容(JSON)を貼り付け、「Update」をクリックします。

image.png

[
  {
    "name": "sys_id",
    "type": "string",
    "optional": false,
    "control_type": "text",
    "label": "Sys ID"
  },
  {
    "name": "record",
    "type": "object",
    "optional": false,
    "properties": [
      {
        "control_type": "text",
        "label": "Location",
        "type": "string",
        "name": "location"
      },
      {
        "control_type": "text",
        "label": "Serial number",
        "type": "string",
        "name": "serial_number"
      }
    ],
    "label": "Record"
  }
]

※上記のようなスキーマ適用方法に関しては、以下もあわせて参考ください。

7.以下の通りスキーマが生成されたことを確認し、「record」オブジェクト以下の階層に必要なフィールドを追加します。

image.png

※ネストされたフィールドの設定手順は以下を参照ください。

また、レコード追加の場合は、「Sys ID」フィールドは削除してください。(更新の際は「Sys ID」が必要となるため、残しておいてください)

### 8.Itemsに必要な値をセットします。

Sys IDにはService Nowのレコードごとのレコード識別子をセットします。

Recordの各フィールドには、追加あるいは更新したい値をセットします。

image.png

Step 4

1.ServiceNowコネクタを追加します。

image.png

2.「Custom action」を追加します。

image.png

3.「Setup manually」をクリックします。

image.png

Action name

任意の名称

Method

POST

Path

/api/now/v1/batch

Request type

JSON request body

Rsponse type

JSON response

Input

Request body parameters

以下の記事を参考に以下のJSONをコピー&ペーストし、スキーマを生成します。

[
  {
    "control_type": "text",
    "label": "Batch request ID",
    "name": "batch_request_id",
    "type": "string",
    "optional": false
  },
  {
    "name": "rest_requests",
    "type": "array",
    "optional": false,
    "properties": [
      {
        "name": "id",
        "type": "string",
        "optional": false,
        "control_type": "text",
        "label": "ID"
      },
      {
        "name": "exclude_response_headers",
        "type": "boolean",
        "optional": false,
        "control_type": "checkbox",
        "label": "Exclude response headers",
        "render_input": {},
        "parse_output": {},
        "toggle_hint": "Select from option list",
        "toggle_field": {
          "label": "Exclude response headers",
          "control_type": "text",
          "toggle_hint": "Use custom value",
          "name": "exclude_response_headers",
          "type": "boolean",
          "optional": false
        }
      },
      {
        "name": "headers",
        "type": "array",
        "optional": false,
        "properties": [
          {
            "name": "name",
            "type": "string",
            "optional": false,
            "control_type": "text",
            "label": "Name"
          },
          {
            "name": "value",
            "type": "string",
            "optional": false,
            "control_type": "text",
            "label": "Value"
          }
        ],
        "of": "object",
        "label": "Headers"
      },
      {
        "name": "url",
        "type": "string",
        "optional": false,
        "control_type": "text",
        "label": "URL"
      },
      {
        "name": "method",
        "type": "string",
        "optional": false,
        "control_type": "text",
        "label": "Method"
      },
      {
        "name": "body",
        "type": "string",
        "optional": false,
        "control_type": "text",
        "label": "Body"
      }
    ],
    "of": "object",
    "label": "Rest requests"
  }
]

上記スキーマを適用すると、次のようなスキーマが生成されます。

image.png

Data

以下の通りセットします。

image.png

Batch request ID

formulaへ切り替え、 workato.uuid と入力します。

Rest requests source list

Step3の records をセットします。

ID

formulaへ切り替え、 workato.uuid と入力します。

Exclude response headers

特に指定が無い限り「Yes」を選択します。

Headers

Input modeを「Fixed list」に切り替えたうえで、次の通り設定します。

Item #1
  • Name: Content-Type
  • Value: application/json
Item #2
  • Name: Accept
  • Value: application/json
URL
追加の場合

/api/now/v2/table/<Step 2の'table'>と入力します。

更新の場合

/api/now/v2/table/<Step 2の'table'>/<Step 3の'Sys ID'>と入力します。

Method

追加の場合は「POST」、更新の場合は「PATCH」と入力します。

Body

formulaへ切り替え、<Step 3の'Record'>.to_json.encode_base64 と入力します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0