# AmplifyからServiceNowへの更新

このページでは、[Webhooks](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/webhooks)を使用してServiceNowのチケットログを自動更新する方法を、[Amplify](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/deploying-nexthink-in-non-vdi-environment/configure-amplify)から実行されるリモートアクションやワークフローを通じて説明します。

構成に基づいて、自動更新は次の場合に発生します。

* リモートアクションやワークフローがトリガーされた場合。
* リモートアクションやワークフローが完了した場合。

{% hint style="info" %}
このページのコードサンプルは、次の方法でServiceNowのやり取りにも適用できます:

Webhookの**NQL条件**で`external_source== "SNOW-Incident"`を`external_source== "SNOW-Interaction"`に置き換えます。

Webhookの**リソース**フィールドで`/table/incident/`を`/table/interaction/`に置き換えます。
{% endhint %}

## ServiceNow用のコネクター認証情報を構成する

[コネクター認証情報](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/connector-credentials)の構成ページから:

1. **HTTPS**オプションを**プロトコル**のドロップダウンから選択します。
2. インスタンスのURLルート`https://<instancename>.service-now.com/`を**URLアドレス**フィールドに貼り付けます。
   * 他のURL例については[connector credential](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/connector-credentials#connectorcredentials-connectorcredentialsforhttpshttpsprotocol)文書を参照してください。

```
https://XXXXXXXXXX.service-now.com/
```

3. **OAuth 2.0 - クライアント認証情報**オプションを**認証**ドロップダウンから選択します
   * **アクセストークンURL**、**クライアントID**、**クライアントシークレット**、**スコープ**フィールドを[connector credential](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/connector-credentials#connectorcredentials-supportedauthorizationmechanismsauthorizationtype)の説明に従って記入します。
4. 認証情報を**保存**します。

<figure><img src="https://3549141153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeLm8O7QKZDn6z806e7Sv%2Fuploads%2Fgit-blob-bf5c6c5b6856a839765a0e6f6e4d27d831915195%2FUpdatingServiceNowFromAmplifyRA_01Connector.png?alt=media" alt=""><figcaption></figcaption></figure>

## Webhookの構成

次のセクションでは、ServiceNowを更新するための2つのシナリオについて詳しく説明します。 各シナリオの手順は非常に似ており、リモートアクションとワークフローのNQL条件とペイロードがシナリオごとに異なります。

### リモートアクションやワークフローがトリガーされたときのServiceNow更新

NexthinkでリモートアクションやワークフローがトリガーされたときにServiceNowのインシデントチケットログを自動的に更新するWebhookを設定します。

最初にWebhook用の[コネクター認証情報](#updatingservicenowfromamplify-configuringwebhookstoupdateservicenowwhenaremoteactionistriggered)をセットアップしてください。

1. [Webhook構成ページ](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/webhooks/managing-webhooks)から、次の**NQL条件**を挿入します。 より多くの例については[Webhook NQL条件の構成](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/managing-webhooks/configuring-webhook-nql-conditions#configuringwebhooknqlconditions-validnqlconditionsexamplesforalert-relatedwebhooksnqlconditionexampl)文書を参照してください。
   * NQL条件を入力した後、システムは**ペイロード**の[許可されるプレースホルダー](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/managing-webhooks/configuring-webhook-fields_-method-resource-and-payload#configuringwebhookfields-method-resource-andpayload-usingdatamodelvariablesasplaceholdersinthepayloa)をリストします。

<table data-header-hidden><thead><tr><th width="185"></th><th></th></tr></thead><tbody><tr><td>リモートアクションの<br>NQL条件</td><td><pre><code>remote_action.executions
| where internal_source == "Amplify" 
  And external_reference != "undefined" 
  And external_source == "SNOW-Incident" 
  And status == in_progress 
  and remote_action.nql_id != "undefined"
| list 
  remote_action.name , 
  remote_action.execution.request_time, 
  remote_action.execution.account_name, 
  remote_action.execution.external_reference
</code></pre></td></tr><tr><td>ワークフローの<br>NQL条件</td><td><pre><code>workflow.executions
| where internal_source == "Amplify" 
  And external_reference != "undefined" 
  And external_source == "SNOW-Incident" 
  And device.name != null 
  And user.name != null
  And outcome == null
  And status == in_progress 
  and workflow.nql_id != "undefined"
| list 
  workflow.name , 
  workflow.execution.request_time,  
  workflow.execution.external_reference
</code></pre></td></tr></tbody></table>

{% hint style="info" %}
ワークフローとリモートアクションの処理中に、複数のイベントが送信され、詳細とともに元のイベントが更新されます。 上記のクエリと使用される条件により、最も完全なイベントのみがServiceNowを更新するために使用されます。
{% endhint %}

2. このWebhookに対して、以前に設定した[コネクタの資格情報](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/connector-credentials)を選択してください。
3. **Method**のドロップダウンからPATCHオプションを選択してください。
4. **Resource**フィールドに次のAPIを挿入してください。

<table data-header-hidden><thead><tr><th width="186"></th><th></th></tr></thead><tbody><tr><td>リモートアクションのためのリソースAPI</td><td><pre><code>api/now/v1/table/incident/{{remote_action.execution.external_reference}}
</code></pre></td></tr><tr><td>ワークフローのためのリソースAPI</td><td><pre><code>api/now/v1/table/incident/{{workflow.execution.external_reference}}
</code></pre></td></tr></tbody></table>

`{{remote_action.execution.external_reference}}`と`{{workflow.execution.external_reference}}`は、Amplify拡張機能からリモートアクションまたはワークフローがトリガーされたときに自動的にServiceNowのチケット参照で埋められるプレースホルダーです。

詳しくは、このページの一番下にある[F.A.Q](#updatingservicenowfromamplify-f.a.q)セクションを参照してください。

5. **Payload**を挿入し、以下のメッセージ例を使用してください：

<table data-header-hidden><thead><tr><th width="186"></th><th></th></tr></thead><tbody><tr><td>リモートアクションのためのペイロード</td><td><pre><code>{"work_notes": "このチケットのためのリモートアクション{{remote_action.remote_action.name}}が、Amplifyユーザー{{remote_action.execution.account_name}}から{{remote_action.execution.request_time}}にトリガーされました"}
</code></pre></td></tr><tr><td>ワークフローのためのペイロード</td><td><pre><code>{"work_notes": "このチケットのためのワークフロー{{workflow.workflow.name}}が、Amplifyから{{workflow.execution.request_time}}にトリガーされました"}
</code></pre></td></tr></tbody></table>

6. 初めての設定の際には、テストせずに**webhookを保存**し、[Amplify](https://docs.nexthink.com/platform/ja/configuring_nexthink/deploying-nexthink-in-non-vdi-environment/configure-amplify#amplify-recordingremoteactionsinathird-partyitsupporttool-servicenowamplifyservicenow)の文書を参照して、ServiceNowからAmplifyでリモートアクションやワークフローを実行し、webhookが正しく動作するか確認してください。
   * **Send test**は、AmplifyのリモートアクションまたはワークフローがServiceNowでトリガーされ、**Resource**のプレースホルダー`{{....}}`のインシデント参照値を生成するまで、Webhookを正常にテストすることはできません。
   * ServiceNow から手動で `remote_action.execution.external_reference` または `workflow.execution.external_reference` の値を取得し、Webhook の設定をテストするには、[F.A.Q](#how-do-i-manually-retrieve-the-servicenow-ticket-remote_action.execution.external_reference-value-to) セクションを参照してください。

{% hint style="info" %}
NexthinkインスタンスとWebアプリケーションを統合し、Registry経由で設定の詳細を展開するためのAmplifyの設定方法については、[Amplifyのインストールと設定ガイド](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/deploying-nexthink-in-non-vdi-environment/configure-amplify/installation-and-configuration)を参照してください。
{% endhint %}

<figure><img src="https://3549141153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeLm8O7QKZDn6z806e7Sv%2Fuploads%2Fgit-blob-79b8c1244ef3257505d7c9f6a4648b61f19da044%2FUpdatingServiceNowFromAmplifyRA_01Webhook.png?alt=media" alt=""><figcaption></figcaption></figure>

### リモートアクションまたはワークフローが完了した時にServiceNowを更新するためのWebhookを設定します。

Nexthink で Webhook を設定し、リモートアクションまたはワークフローの完了結果の詳細で ServiceNow のインシデントチケットログを自動的に更新します。

Webhookのために[コネクタの資格情報](#updatingservicenowfromamplify-configuringwebhookstoupdateservicenowwhenaremoteactionistriggered)を最初に設定しておくことを忘れないでください。

1. [Webhook設定ページ](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/webhooks/managing-webhooks)から、以下の**NQL条件**を挿入してください。 Webhook NQL 条件の設定については、[Webhook NQL 条件の設定](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/managing-webhooks/configuring-webhook-nql-conditions#configuringwebhooknqlconditions-validnqlconditionsexamplesforalert-relatedwebhooksnqlconditionexampl) のドキュメントを参照してください。
   * NQL条件を入力すると、システムは**Payload**の[許可されたプレースホルダー](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/managing-webhooks/configuring-webhook-fields_-method-resource-and-payload#configuringwebhookfields-method-resource-andpayload-usingdatamodelvariablesasplaceholdersinthepayloa)をリストアップします。

<table data-header-hidden><thead><tr><th width="194"></th><th></th></tr></thead><tbody><tr><td>リモートアクションのためのNQL条件</td><td><pre><code>remote_action.executions
| where internal_source == "Amplify" 
  And external_reference != "undefined" 
  And external_source == "SNOW-Incident" 
  And status in [failure, success , expired] 
  and remote_action.nql_id != "undefined"
| list remote_action.name , 
  remote_action.execution.request_time, 
  remote_action.execution.time, 
  remote_action.execution.status, 
  remote_action.execution.status_details, 
  remote_action.execution.inputs, 
  remote_action.execution.outputs, 
  remote_action.execution.account_name, 
  remote_action.execution.external_reference
</code></pre></td></tr><tr><td>ワークフローのためのNQL条件</td><td><pre><code>
workflow.executions
| where internal_source == "Amplify"
 And external_reference != "undefined" 
 And external_source == "SNOW-Incident" 
 And status in [failure, success, expired, cancelled] 
 And workflow.nql_id != "undefined"
| list workflow.name ,
 workflow.execution.request_time, 
 workflow.execution.time, 
 workflow.execution.status, 
 workflow.execution.status_details, 
 workflow.execution.inputs, 
 workflow.execution.outcome, 
 workflow.execution.external_reference
</code></pre></td></tr></tbody></table>

2. このWebhookに対して、以前に設定した[コネクタの資格情報](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/connector-credentials)を選択してください。
3. **Method**のドロップダウンからPATCHオプションを選択してください。
4. **Resource**フィールドに次のAPIを挿入してください。

<table data-header-hidden><thead><tr><th width="186"></th><th></th></tr></thead><tbody><tr><td>リモートアクションのためのリソースAPI</td><td><pre><code>api/now/v1/table/incident/{{remote_action.execution.external_reference}}
</code></pre></td></tr><tr><td>ワークフローのためのリソースAPI</td><td><pre><code>api/now/v1/table/incident/{{workflow.execution.external_reference}}
</code></pre></td></tr></tbody></table>

`{{remote_action.execution.external_reference}}`と`{{workflow.execution.external_reference}}`は、Amplify拡張機能からリモートアクションまたはワークフローがトリガーされたときに自動的にServiceNowのチケット参照で埋められるプレースホルダーです。

詳しくは、このページの一番下にある[F.A.Q](#updatingservicenowfromamplify-f.a.q)セクションを参照してください。

5. **Payload**を挿入し、以下のメッセージ例を使用してください：

<table data-header-hidden><thead><tr><th width="186"></th><th></th></tr></thead><tbody><tr><td>リモートアクションのためのペイロード</td><td><pre><code>{"work_notes":"Amplifyユーザー{{remote_action.execution.account_name}}によってこのチケットのためにトリガーされたリモートアクション{{remote_action.remote_action.name}}のステータスは以下の通りです。\nリクエスト時間：{{remote_action.execution.request_time}} \n実行時間：{{remote_action.execution.time}} \nステータス：{{remote_action.execution.status}} \nステータス詳細：{{remote_action.execution.status_details}} \n入力：{{remote_action.execution.inputs.as(format = text)}} \n出力：{{remote_action.execution.outputs.as(format = text)}}"}
</code></pre></td></tr><tr><td>ワークフローのためのペイロード</td><td><pre><code>{ "work_notes": "Amplifyからこのチケットのためにトリガーされたワークフロー{{workflow.workflow.name}}のステータスは以下の通りです。リクエスト時間：{{workflow.execution.request_time}} 実行時間：{{workflow.execution.time}} ステータス：{{workflow.execution.status}} ステータス詳細：{{workflow.execution.status_details}} 入力：{{workflow.execution.inputs}} 結果：{{workflow.execution.outcome"}}}
</code></pre></td></tr></tbody></table>

6. 初めての設定の際には、テストせずに**webhookを保存**し、[Amplify](https://docs.nexthink.com/platform/ja/configuring_nexthink/deploying-nexthink-in-non-vdi-environment/configure-amplify#amplify-recordingremoteactionsinathird-partyitsupporttool-servicenowamplifyservicenow)の文書を参照して、ServiceNowからAmplifyにリモートアクションを実行し、webhookが正しく動作するか確認してください：
   * **Send test**は、ServiceNowでAmplifyからのリモートアクションをトリガーするまで、Webhookを正常にテストすることはできません。このとき、**Resource**プレースホルダー`{{...}}`のインシデント参照値が生成されます。
   * ServiceNowから手動で`remote_action.execution.external_reference`または`workflow.execution.external_reference`の値を取得し、Webhook設定をテストするには、[F.A.Q](#how-do-i-manually-retrieve-the-servicenow-ticket-remote_action.execution.external_reference-value-to)セクションを参照してください。

{% hint style="info" %}
NexthinkインスタンスとWebアプリケーションを統合し、Registryを通じて設定の詳細を展開する方法については、[Amplifyのインストールと設定ガイド](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/deploying-nexthink-in-non-vdi-environment/configure-amplify/installation-and-configuration)を参照してください。
{% endhint %}

***

## F.A.Q

#### ServiceNowでAmplifyがインシデントまたは対話ログを更新しているかどうかを確認するにはどうすればよいですか？

[Amplify](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/deploying-nexthink-in-non-vdi-environment/configure-amplify)の文書は、サービスNowログにAmplify拡張を使用してリモートアクションやワークフローを登録する方法を説明しています。 つまり、このページに記載されているWebhook設定に従った後のことです。

#### **Resource**フィールド内の`{{remote_action.execution.external_reference}}`と`{{workflow.execution.external_reference}}`プレースホルダーの値は何ですか？

Amplify Webhookのプロセスは、ServiceNowの提供する一連の指定されたURLを読み込んで、チケットの`sys_id`とタイプ（インシデントまたは対話）を見つけるために照合することで、ServiceNow URLから`external_reference`値を取得することにあります。

次に、Amplifyはこの`external_reference`値を`remote_action`または`workflow`情報と共にNexthinkプラットフォームに送信し、Webhookはこれらの値を使用してWebhookの**Resource**プレースホルダー（例：`{{remote_action.execution.external_reference}}`）を置き換えます。

#### Webhook設定をテストするためのServiceNow `remote_action.execution.external_reference`値の手動取得方法は？

ServiceNowのブラウザページからAmplifyでリモートアクションを実行した後：

1. ServiceNowのインシデントまたは対話URLから`external_reference`を取得します。

* ワークスペースビューでのURL例：

<figure><img src="https://3549141153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeLm8O7QKZDn6z806e7Sv%2Fuploads%2Fgit-blob-05af857a451b10c44e6d3cd7ba3fe33f371a9e5f%2FUpdatingServiceNowAplify_URL-01.png?alt=media" alt=""><figcaption></figcaption></figure>

* クラシックビューでのURL例：

<figure><img src="https://3549141153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeLm8O7QKZDn6z806e7Sv%2Fuploads%2Fgit-blob-1fd492534a2e501473b4dac37f35e73120ff2018%2FUpdatingServiceNowfromAmplify-URL-02.png?alt=media" alt=""><figcaption></figcaption></figure>

Nexthinkの[Webhook設定](#updatingservicenowfromamplify-configuringwebhookstoupdateservicenowwhenaremoteactionistriggered-1)ページから：

2. ServiceNow URLから手動で取得した`external_reference`を使って、**Resource**プレースホルダー`{{remote_action.execution.external_reference}}`を置き換えます。 たとえば：

```
api/now/v1/table/incident/32dd789083xxxxxxxxxxxxxxxxxxxxx
```

3. **Webhook設定**をチェックするためにテストを送信してください。 テストが成功したことを確認した後、正しいプレースホルダーで**Resource**を置き換えてWebhookを保存します。

```
api/now/v1/table/incident/{{remote_action.execution.external_reference}}
```

#### NexthinkプラットフォームでServiceNowのインシデントまたは対話`sys_id`を確認する方法は？

このページに記載されているWebhook設定に従い、ServiceNowでAmplify拡張機能を使用してリモートアクションを実行した後、Nexthinkのインベスティゲーションページで対応するNQLクエリを実行してチケット`sys_id`を取得します。

**External reference**の下で`sys_id`、**External source**の下でチケットタイプ（`external_source== "SNOW-Incident"`または`external_source== "SNOW-Interaction"`）を見つけます。

<figure><img src="https://3549141153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeLm8O7QKZDn6z806e7Sv%2Fuploads%2Fgit-blob-12a22ccd3b8ee2eee2533878deb0c59b9d420a7d%2Fservicenowamp-1713527391.png?alt=media" alt="Checking ServiceNow incident or interaction ID in the Nexthink platform."><figcaption></figcaption></figure>

***

関連トピック

* [Amplify](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/deploying-nexthink-in-non-vdi-environment/configure-amplify)
* [ServiceNowエージェントワークスペース用Amplifyの設定](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/deploying-nexthink-in-non-vdi-environment/configure-amplify/installation-and-configuration/integrating-amplify-with-web-applications/configuring-amplify-for-servicenow-agent-workspace)
* [ServiceNowオペレーションズワークスペース用Amplifyの設定](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/deploying-nexthink-in-non-vdi-environment/configure-amplify/installation-and-configuration/integrating-amplify-with-web-applications/configuring-amplify-for-servicenow-operations-workspace)
* [コネクタ資格情報](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/connector-credentials)
* [ServiceNow のインシデント作成](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/webhooks/webhook-use-cases-setup/creating-an-incident-in-servicenow)
* [Amplifyのインストールと設定](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/deploying-nexthink-in-non-vdi-environment/configure-amplify/installation-and-configuration)
* [Webhookの管理](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/webhooks/managing-webhooks)
* [Webhookフィールドの設定: Method、Resource、およびPayload](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/webhooks/managing-webhooks/configuring-webhook-fields_-method-resource-and-payload)
* [WebhookのNQL条件の設定](https://docs.nexthink.com/platform/ja/configuring_nexthink/bringing-data-into-your-nexthink-instance/integrating-nexthink-with-third-party-tools/outbound-connectors/webhooks/managing-webhooks/configuring-webhook-nql-conditions)
