サードパーティデータ連携のサンプルスクリプト

  • リリースバージョン: Xanadu
  • 更新日 2024年08月01日
  • 所要時間:3分
  • リモートテーブルスクリプトは、サードパーティアプリケーションからレコードをプルするように設計することができます。このスクリプトは、リモートテーブル内のデータにアクセスするクエリが作成されたときに呼び出されます。

    統合ハブでリモートテーブルを使用するには、サードパーティアプリケーションと連携する統合ハブスポークを特定する必要があります。スポークは、アプリケーションからさまざまなデータのサブセットを取得するために作成されたフローデザイナーアクションで構成されます。

    たとえば、Salesforce アプリケーションからアカウント情報を取得する必要がある場合は、Salesforce スポークとすべてのアカウントを取得アクションを使用します。このアクションにアクセスするリモートテーブルスクリプトの例については、以下を参照してください。

    (function executeQuery(v_table, v_query) {
      try {
        // prepare inputs for the spoke actions 
        // Get All Accounts action does not have any inputs).
        var inputs = {};
    
        // call spoke action
        var outputs = sn_fd.FlowAPI.executeAction(
                                    "sn_salesforce_spok.get_all_accounts", inputs);
    
        // check if Action was completed successfully
        if (outputs.status != "Success") {
          throw new Error(outputs.errorMessage);
        }
    
        // extract payload from the action outputs
        var accounts = outputs.accounts.data;
    
        // map action output data to the remote table columns and Sys Id
        for (var i = 0; i < accounts.length; i++) {
          v_table.addRow({
            "u_sf_account_id": accounts[i].name,
            "u_sf_account_name": accounts[i].label,
            // assign remote table Sys Id to the primary key of the third-party
            // record
            "sys_id": accounts[i].name,
          });
        }
    
      // process errors 
      } catch (error) {
         gs.addErrorMessage("Error trying to retrieve  Salesforce Accounts." +
                            "Please contact System Administrator.");
         gs.addErrorMessage("System Error: " + error.message);
      }
    
    })(v_table, v_query);
    
    注:
    リモートテーブルスクリプトから呼び出せない統合ハブアクションもあります。具体的には、スクリプトからデータストリームアクションを呼び出すことはできません。使用するアクションがデータストリームアクションである場合は、REST ステップに基づいて独自のアクションを作成する必要があります。アクションを簡単に作成するには、既存のアクションをコピーしてから、目標を達成するために変更することが必要です。カスタムスポークアクションの例については、「リモートテーブル定義で使用する機会を取得するための Salesforce スポークアクションの作成」のトピックを参照してください。