UiPath Documentation
studio-web
latest
false
Studio Web ガイド
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。

チケットの詳細を取得する

Studio Web で API ワークフローを構築して、ServiceNow のインシデントの詳細を取得し、Agents と Maestro で使用するチケット作成者情報を検証します。

このチュートリアルでは、API ワークフローを使用して、後で Agents や Maestro と連携させるチケットの詳細を取得する方法を説明します。

この API ワークフローは、ServiceNow からインシデントの詳細を取得し、可能であれば Salesforce からチケット作成者とその関連会社に関する追加情報を検証して取得することを目的としています。

  1. データ マネージャーを開き、incidentNumber を次のプロパティとともに [入力] プロパティとして追加します。

    • 型: String
    • 説明: 受信チケット番号の参照
    • 必須: True
  2. データ マネージャーで、incidentObject と isValidCallerIdLink を変数として追加し、次のプロパティを設定します。

    • incidentObject — 詳細情報を含むインシデントの詳細を格納します。
      • 型: オブジェクト
      • 既定値: 空のままにします
    • isValidCallerIdLink — ServiceNow から取得した caller_id_link が有効な URL であるかどうかを確認します。
      • 型: ブール
      • 既定値は false です
  3. [Debug configuration] ウィンドウを開きます。必須の incidentNumber フィールドに「INC0026701」と入力します。

  4. [コネクタ] アクティビティを追加し、ServiceNow アクティビティ [インシデントをインシデント番号で検索] を使用するように設定します。これにより、入力として入力したインシデント番号に基づいてインシデントの詳細が取得されます。

    1. ServiceNow コネクションを選択します。
    2. incident ID を変数 incident ID > incident Number > に接続します。
    3. アクティビティ コンテキストの出力の名前を $context.outputs.incident_1に変更します。
  5. 前の手順でインシデントが見つかったかどうかを確認するには、次の条件で [条件分岐 (if )] アクティビティを追加します。

    $context.outputs.incident_1.content && $context.outputs.incident_1.content.length > 0
    $context.outputs.incident_1.content && $context.outputs.incident_1.content.length > 0
    
  6. [Then] 分岐で、インシデントが見つかった場合は、caller_id_linkの検証に進み、詳細情報を取得します。[ トライ キャッチ] アクティビティを追加します。

    1. [Try] ブロック内に、次のコードを記述した [スクリプト] アクティビティを追加します。

      const callerIdLink = $context.outputs.incident_1.content[0].caller_id_link;
      const urlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i;
      $context.variables.isValidCallerIdLink = (callerIdLink && urlRegex.test(callerIdLink));
      return $context.variables.isValidCallerIdLink;
      const callerIdLink = $context.outputs.incident_1.content[0].caller_id_link;
      const urlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i;
      $context.variables.isValidCallerIdLink = (callerIdLink && urlRegex.test(callerIdLink));
      return $context.variables.isValidCallerIdLink;
      

      アクティビティの名前を「リンクcaller_id検証」に、コンテキストの出力名を「 $context.outputs.Validate_Caller_ID_Link」に変更します。

    2. 同じ [Try] ブロック内に、[条件分岐 (if)] アクティビティを条件として「$context.variables.isValidCallerIdLink」を追加します。アクティビティの名前を「If the caller_id_link is valid」に、コンテキストの出力名を「 $context.outputs.If_Caller_ID_Valid」に変更します。

    3. 前の [条件分岐 (if)] アクティビティの [Then] 分岐 (リンクが有効) に、以下の設定でコネクタ アクティビティ [Service Now の HTTP 要求] を追加します。

      • ServiceNow 接続 — ServiceNow 開発者アカウント
      • メソッド - GET
      • 要求 URL—
        $context.outputs.incident_1.content[0].caller_id_link
        ```Rename the activity to "Get Ticket Creator". The context output name remains as `$context.outputs.ServiceNow_HTTP_Request_1`.
        $context.outputs.incident_1.content[0].caller_id_link
        ```Rename the activity to "Get Ticket Creator". The context output name remains as `$context.outputs.ServiceNow_HTTP_Request_1`.
        
    4. 前の [条件分岐 (if)] アクティビティの [Else (リンクが無効)] 分岐に、次のコードを記述した [スクリプト] アクティビティを追加します。

      console.error("Invalid caller_id_link, skipping 'Get Ticket Creator' activity.");
      return null;
      console.error("Invalid caller_id_link, skipping 'Get Ticket Creator' activity.");
      return null;
      

      アクティビティの名前を「無効なcaller_id_linkログ」に、コンテキストの出力名を $context.outputs.Log_Invalid_Caller_IDに変更します。

    5. [条件分岐 (if)] アクティビティの外、ただし [トライ] ブロック内に、以下のコードを含むスクリプト アクティビティを追加します。このアクティビティは、最初のインシデントの詳細と取得した作成者の詳細を 1 つのインシデント オブジェクトに結合します。

      const incident = $context.outputs.incident_1.content[0];
      let creatorDetails = null;
      const creatorOutput = $context.outputs.ServiceNow_HTTP_Request_1.content;
      if (creatorOutput && Array.isArray(creatorOutput) && creatorOutput.length > 0) {
        creatorDetails = creatorOutput[0];
      } else if (creatorOutput && typeof creatorOutput === 'object' && creatorOutput !== null) {
        creatorDetails = creatorOutput;
      }
      
      let companyDetails = null;
      const companyOutput = $context.outputs.ServiceNow_HTTP_Request_1.content;
      if (companyOutput && typeof companyOutput === 'object' && companyOutput !== null) {
        companyDetails = companyOutput;
      } else if (companyOutput && Array.isArray(companyOutput) && companyOutput.length > 0) {
        companyDetails = companyOutput[0];
      }
      
      return {
        ...incident,
        creator: creatorDetails,
        company: companyDetails
      };
      const incident = $context.outputs.incident_1.content[0];
      let creatorDetails = null;
      const creatorOutput = $context.outputs.ServiceNow_HTTP_Request_1.content;
      if (creatorOutput && Array.isArray(creatorOutput) && creatorOutput.length > 0) {
        creatorDetails = creatorOutput[0];
      } else if (creatorOutput && typeof creatorOutput === 'object' && creatorOutput !== null) {
        creatorDetails = creatorOutput;
      }
      
      let companyDetails = null;
      const companyOutput = $context.outputs.ServiceNow_HTTP_Request_1.content;
      if (companyOutput && typeof companyOutput === 'object' && companyOutput !== null) {
        companyDetails = companyOutput;
      } else if (companyOutput && Array.isArray(companyOutput) && companyOutput.length > 0) {
        companyDetails = companyOutput[0];
      }
      
      return {
        ...incident,
        creator: creatorDetails,
        company: companyDetails
      };
      

    アクティビティの名前を「JS - Incident Object」に変更します。コンテキスト出力名は $context.outputs.Javascript_1のままです。6. インシデント オブジェクトを変数に割り当てる: 次の設定で [代入 ] アクティビティを追加します。

    • 変数 - 最初に定義した incidentObject 変数を選択します。

    • 値を設定 - 前のスクリプト アクティビティのコンテキスト名を参照します。

      $context.outputs.Javascript_1
      $context.outputs.Javascript_1
      

      アクティビティの名前を「incident オブジェクトを割り当て」に変更します。コンテキスト出力名は $context.outputs.Assign_1のままです。

    1. 現在の [トライ キャッチ] アクティビティの [Catch] ブロックに、次のコードを記述した [スクリプト] アクティビティを追加します。

      let errorMessage = `Error in Try_Catch_1: ${$error.title || 'Unknown Error'}`;
      if ($error.detail) {
        errorMessage += `\nDetails: ${$error.detail}`;
      }
      if ($error.data && $error.data.status) {
        const statusCode = $error.data.status;
        if (statusCode === 0 || statusCode === -1) {
          errorMessage += "\nNetwork error: Unable to connect to ServiceNow.";
        } else if (statusCode >= 500 && statusCode < 600) {
          errorMessage += "\nServiceNow server error.";
        }
      }
      console.error(errorMessage);
      console.error("Stack Trace:", $error);
      return null;
      let errorMessage = `Error in Try_Catch_1: ${$error.title || 'Unknown Error'}`;
      if ($error.detail) {
        errorMessage += `\nDetails: ${$error.detail}`;
      }
      if ($error.data && $error.data.status) {
        const statusCode = $error.data.status;
        if (statusCode === 0 || statusCode === -1) {
          errorMessage += "\nNetwork error: Unable to connect to ServiceNow.";
        } else if (statusCode >= 500 && statusCode < 600) {
          errorMessage += "\nServiceNow server error.";
        }
      }
      console.error(errorMessage);
      console.error("Stack Trace:", $error);
      return null;
      

      アクティビティの名前を「Log error details」に、コンテキストの出力名を「 $context.outputs.Log_Error_Catch」に変更します。

    2. エラーが発生した場合は、[ 代入 ] アクティビティを追加して、ServiceNow の初期情報を含む簡略化されたインシデント オブジェクトを使用します。

      • 変数 - 最初に定義した incidentObject 変数を選択します。
      • 値を設定— ''' (($incidentDetails) => ({ id: $incidentDetails.sys_id,number: $incidentDetails.number,short_description: $incidentDetails.short_description、description: $incidentDetails.description、状態: $incidentDetails.state、緊急性: $incidentDetails.urgency、影響: $incidentDetails.impact、opened_at: $incidentDetails.opened_at、closed_at: $incidentDetails.closed_at}))($context.outputs.curated_search_incident_1.content[0])
       The activity name and the context output name remain as they are.
      
       The activity name and the context output name remain as they are.
      
      
  7. [トライ キャッチ] アクティビティを終了し、[Else] 分岐に空の応答を追加します。[応答] アクティビティの名前を「結果が見つかりませんでした。」に変更します。

  8. 作成者のメール アドレスと企業アカウント ID に関する十分な情報がインシデント オブジェクトに含まれているかどうかを確認するには、次の条件を指定して [条件分岐 (if )] アクティビティを追加します。

    $context.variables.incidentObject && $context.variables.incidentObject.creator && $context.variables.incidentObject.creator.email && $context.variables.incidentObject.company && $context.variables.incidentObject.company.account_id
    $context.variables.incidentObject && $context.variables.incidentObject.creator && $context.variables.incidentObject.creator.email && $context.variables.incidentObject.company && $context.variables.incidentObject.company.account_id
    
    1. [Then] 分岐にコネクタアクティビティを追加し、Salesforce アクティビティを使用するように設定します。 SOQL を使用して検索。アクティビティの名前を「連絡先を取得」に、コンテキストの出力名を $context.outputs.soqlQuery_1に変更します。
    2. [ クエリ ] フィールドで [式エディター] を開き、次のように書き込みます。
    "SELECT Id, Name, Email, AccountId FROM Contact WHERE Email = '" + $context.variables.incidentObject.creator.email + "' LIMIT 1"
    "SELECT Id, Name, Email, AccountId FROM Contact WHERE Email = '" + $context.variables.incidentObject.creator.email + "' LIMIT 1"
    
    1. [Then] 分岐に、[条件] を設定した [条件分岐 (if)] アクティビティを追加します $context.outputs.soqlQuery_1.content && $context.outputs.soqlQuery_1.content.length > 0
     Rename the activity to "If Contact Found" and the context output name to `$context.outputs.If_Contact_Found`. This conditional activity checks if a contact was found in Salesforce.
     Rename the activity to "If Contact Found" and the context output name to `$context.outputs.If_Contact_Found`. This conditional activity checks if a contact was found in Salesforce.
    
    1. [連絡先が見つかった場合] アクティビティの [Then ] 分岐に コネクタ アクティビティを追加し、 Salesforce で [アカウントを取得] アクティビティを使用するように設定します。

      • Salesforce 接続 — Salesforce 開発者アカウント
      • アカウント ID—
        $context.variables.incidentObject.company.account_id
        $context.variables.incidentObject.company.account_id
        

      コンテキスト出力の名前を $context.outputs.curated_account_1に変更します。このアクティビティは、詳細情報を含むインシデント オブジェクトのaccount_idを使用して、Salesforce からアカウントの詳細を取得します。

    2. [連絡先が見つかった場合] アクティビティの [Then ] 分岐に [繰り返し (コレクションの各要素)] アクティビティを追加し、[ $context.outputs.soqlQuery_1.content検索対象] を設定します。このループは、Salesforce 取引先責任者検索の結果を反復処理します (ただし、SOQL クエリは 1 に制限されています)。ループ内で、見つかった連絡先に関連するケースの詳細の取得を試みます。

    3. [繰り返し (コレクションの各要素)] ループの本体内に、[コネクタ] アクティビティ [Service Now の HTTP 要求] を次の設定で追加します。

      • ServiceNow 接続 — Salesforce 開発者アカウント
      • メソッド - GET
      • 要求 URL—
        "/services/data/v64.0/sobjects/Case/" + $currentItem.Id
        "/services/data/v64.0/sobjects/Case/" + $currentItem.Id
        

      アクティビティの名前を「ケースの詳細」に変更します。コンテキスト出力名はそのまま残ります。

    4. [繰り返し (コレクションの各要素)] ループを終了し、空の [応答] アクティビティを追加します。

    5. [連絡先が見つかった場合] アクティビティの [Else] 分岐に、次の [応答] アクティビティを追加します。

      • 応答—
        No Salesforce Contact found for the incident creator email."
        No Salesforce Contact found for the incident creator email."
        

      アクティビティの名前を「連絡先が見つかりませんでした。」に変更します。

このページは役に立ちましたか?

接続

ヘルプ リソース サポート(opens in new window)

学習する UiPath アカデミー(opens in new window)

質問する UiPath フォーラム(opens in new window)

最新情報を取得