ケースビューコンポーネントインスタンスの構成
ユーザーが Web サイトに埋め込み、Web サイト上のケース関連のアクティビティに直接アクセスできるように、ケースビューコンポーネントインスタンスを構成します。
始める前に
ケースビューコンポーネントインスタンスを構成するには、次のセットアップが必要です。
- インスタンスで Web 埋め込み可能 を有効にします。詳細については、「Web 埋め込み可能 のアクティブ化」を参照してください。
- カスタム URL をインスタンス URL として設定。
- OpenID Connect (OIDC) 認証または非 OIDC 認証を使用して、 ServiceNow コンポーネントを認証します。詳細については、「OIDC を使用した ServiceNow コンポーネントの認証」と「ServiceNow コンポーネントの非 OIDC 認証」を参照してください。
必要なロール:sn_embeddable_core.emb_admin
手順
- 移動先 すべて > Web 埋め込み可能 > ホームページ.
-
ホームページで、[モジュールの作成] を選択するか、既存のモジュールを使用します。
新しいモジュールの作成の詳細については、「 モジュールを作成」を参照してください。
-
モジュールページの [コンポーネント] タブで、ケースビューコンポーネントインスタンスを既存または新しいグループに追加します。
グループを作成してからコンポーネントインスタンスを追加する方法の詳細については、「 グループの作成とコンポーネントインスタンスの追加」を参照してください。
- オプション:
[ 静的プレビューを表示 ] オプションを切り替えて、ライブプレビューが利用できないときにコンポーネントの視覚的表現を表示します。
注:有効にすると、グローバルプロパティまたはコンポーネントプロパティへの変更は [プレビュー] タブにリアルタイムで表示されません。
-
ケースビューコンポーネントのインスタンスプロパティを設定します。
- [プレビュー] タブには、コンポーネントプロパティで設定された選択肢に従ってリアルタイムデータが表示されます。
- ケースビューコンポーネントインスタンスに関連するコンポーネントプロパティの説明については、「 [ケース] ビューのコンポーネントプロパティ」を参照してください。
-
[ CORS ルール ] タブを選択して、CORS ルールを構成します。
CORS ルールの構成の詳細については、「 ServiceNowコンポーネントを埋め込む前に CORS (クロスオリジンリソース共有) ルールを構成する」を参照してください。
-
[コンポーネント] タブを選択します。
アプリケーションスコープに関するメッセージが表示された場合は、スコープを [カスタマーサービスの Web コンポーネント ] に変更して、レコードを編集できるようにします。
-
[埋め込みコードの取得] を選択します。
グローバルコードとコンポーネントコードの両方を表示するポップアップウィンドウが表示されます。
-
[グローバル コード] タブで、生成されたコードを確認し、[ グローバル コードのコピー] を選択します。
グローバル コードは、サードパーティの Web ページに一度だけ追加する必要があります。
import { init, login, logout, startGuestSession } from 'https://demo.servicenow.com/uxasset/externals/sn_embeddable_core/index.jsdbx'; await init({ theme: 'fad87d2ca304121029a4d1aed31e610f', /* sys_id of the theme to use for the embeddable components in your website */ baseURL: 'https://demo.servicenow.com', /* Base URL of the instance to be used for the embeddable components in your website */ authCallback: getTokenCallBack, /* Function which returns the auth token for the current user, required for auth setup */ module: '591800ffc1243610f87714367ed47c6a', /* Demo module */ pageName: document.title, /* Uses the browser's document title as the page name in User analytics experience */ guestTokenCallback: getGuestJWTTokenCallBack, /* Function which returns the guest token for the current user, required for guest validation setup */ cacheComponents: [] /* Pre-caches resources for improved performance. Update component list as per your usage */ }); function getTokenCallBack() { var idToken; /* Get the id token for the current user */ return Promise.resolve(idToken); } function getGuestJWTTokenCallBack() { var guestToken; /* Get the guest token for the current user */ return Promise.resolve(guestToken); } /* Uncomment below function to handle guest session */ // await startGuestSession(); /* Uncomment below functions to handle login and logout once the user logs into your website */ // await login(); // await logout(); - オプション:
[コンポーネント コード] タブで、[ イベント ハンドラーを有効にする ] 切り替えスイッチをスライドさせて、Web ページでのユーザー操作によってトリガーされたイベントを処理します。
注:イベントハンドラーを有効にすると、コンポーネントコードも変更されます。Web 埋め込み可能 におけるイベントハンドラーの詳細については、「拡張ケースビューコンポーネントのイベントハンドラー」を参照してください。
-
[コンポーネントコード] タブで、生成されたコードを確認し、[コンポーネントコードをコピー (Copy component code)] を選択します。
この生成されたコードには、イベントハンドラーの構成も含まれています。
<!-- Module: Demo module Group: Group 1 Instance: Case view 1 --> <sn-embedx-case-view table="sn_customerservice_case" table-view-for-related-list="4006fee3d7600200e5982cf65e6103de" header-configuration-id="1db45f9118520210f8775b8843daf927" action-configuration-id="b226535518520210f8775b8843daf9fb" playbook-stage-orientation="horizontal" visible-horizontal-playbook-stages="5" playbook-activity-view-mode="focused" sys-id="aa5ca024d7700200e5982cf65e61030e"> </sn-embedx-case-view> <!-- The component also includes the following additional properties: hide-activity hide-attachments hide-actions hide-all-related-lists show-custom-tab hide-errors hide-playbook-process-tab selected-playbook-context-id selected-stage-context-id selected-activity-context-id hide-playbook-stages --> <script type="module"> import { getEmbeddables, setEvents, setProperties } from 'https://demo.servicenow.com/uxasset/externals/sn_embeddable_core/index.jsdbx'; const snEmbedxCaseView = document.querySelector('sn-embedx-case-view'); /* Uncomment this code for the default behaviour of the Case View component. // Get the record id and table from the current URL for a standard case. // Optionally, get playbook experience ID, playbook context ID, stage context ID, // and activity context ID for playbook case. const currentURL = new URL(window.location.href); const urlParams = new URLSearchParams(currentURL.search); const tableName = urlParams.get('emb_table'); const sysRecordId = urlParams.get('emb_recordid'); const playbookExperience = urlParams.get('emb_playbook_experience'); const playbookContextId = urlParams.get('emb_playbook_context_id'); const stageContextId = urlParams.get('emb_stage_context_id'); const activityContextId = urlParams.get('emb_activity_context_id'); // Update the sysId and table properties of the componentProperties object. // Optionally, update the playbook experience ID, playbook context ID, // stage context ID, and activity context ID for the playbook case view as well. setProperties(snEmbedxCaseView,{ table:tableName, sysId:sysRecordId, playbookExperience:playbookExperience, selectedPlaybookContextId:playbookContextId, selectedStageContextId:stageContextId, selectedActivityContextId:activityContextId }); */ getEmbeddables(["sn-embedx-case-view"]); const eventHandlers = { 'SN_EMBEDX_CASE_VIEW#COMPONENT_READY' : (e) => { // This event is dispatched when a component is ready and usable. }, 'SN_EMBEDX_CASE_VIEW#COMPONENT_ERROR' : (e) => { // This event is dispatched when a property validation or internal error occurs. var {errorMessage, errorType} = e.detail.payload; console.log(errorMessage, errorType); }, 'SN_EMBEDX_CASE_VIEW#CASE_COMMENT_ADDED' : (e) => { // This event is dispatched when a comment is added in the activity stream. } }; setEvents(snEmbedxCaseView, eventHandlers); </script>
タスクの結果
グローバルコードとコンポーネントコードをサードパーティアドミニストレーターと共有して、ケースビューコンポーネントインスタンスをサードパーティ Web サイトに埋め込む準備ができました。