SoR 内のリモート情報をルックアップ
このユースケースでは、REST API 呼び出しを使用して、リモートの銀行システム (記録システム) で顧客の住宅ローン口座の財務トランザクションの詳細を検索する方法を示します。
コールセンターのエージェントが顧客の問い合わせに応答し、 ServiceNow フォームを使用して新しい FSO ケースを作成します。そのフォームで、コンシューマー、金融口座、カテゴリ、簡単な説明の情報、および関連するメモを手動で入力します。
ServiceNowフォーム内のスクリプトは、コンシューマーおよび金融口座情報を使用して、リモート銀行システム (銀行アプリケーション) 上のリモート REST エンドポイントを呼び出し、金融トランザクションの詳細を取得します。その後、これらの詳細が [ ServiceNow ] フォームに表示されるため、エージェントは、残りの必要なケース情報を手動で入力する前に情報を確認できます。完了すると、FSO ケースが ServiceNow インスタンスにキャッシュされます。
以下は、リモート銀行アプリケーションから受信した財務トランザクションの詳細が FSO ケースフォームに表示されたときにどのように表示されるかの例です。
次の図は、このユースケースシナリオのアプリケーションフローを示しており、必要な処理に関する簡単な説明を示しています。この実装では、リモートバンクアプリケーションから取得したデータはリモートテーブルに格納されます。リモートテーブル はメモリにのみキャッシュされ、 ServiceNow データベーステーブルに保存されることはありません。このシナリオは、対応する ServiceNow データベーステーブルにリモートデータを書き込むことで実装することもできます。シナリオは、GlideRecord API を使用してServiceNowデータベーステーブルにデータを格納する方法を示しています。
|
コード例
(function executeQuery (v_table, v_query) {
// Parameters needed in the request body of the REST endpoint
var requestBody = {
'financial_account':v_query.getParameter('financial_account')
};
// Instantiate the RESTMessageV2 object
var request = new sn_ws.RESTMessageV2();
// Set the HTTP method as "GET"
request.setHttpMethod('get');
// URL of the endpoint on the bank application
request.setEndpoint('https://<yourbankapphost>/api/getTransactionDetails');
// Request body as a string
request.setRequestBody(JSON.stringify(requestBody));
// Call the REST endpoint
var response = request.execute();
// Get the response body
var responseBody = response.getBody();
// Parse the response body into an object
var responseObj = JSON.parse(responseBody);
// Store the response body into a virtual table
v_table.addRow({
sys_id: gs.generateGUID(),
amount: responseObj.amount,
description: responseObj.description,
posting_date: responseObj.posting_date,
transaction_date: responseObj.transaction_date
});
}) (v_table, v_query);コード例
function getRequiredInfo() {
// Instantiate a GlideRecord object with the remote table containing the financial transaction details.
var now_GR = new GlideRecord('transaction_details_remote_table');
// Create a query to obtain the desired financial account
now_GR.addQuery('financial_account', g_form.getValue('financial_account'));
// Execute the query
var result = now_GR.query();
// Display the data in the FSO form
var data = [];
data ['amount'] = result.amount;
data ['description'] = result.description;
data ['posting_date'] = result.posting_date;
data ['transaction_date'] = result.transaction_date;
return data;
}
getRequiredInfo();