サンプル: Xrm.Page.data.process.getActivePath

 

公開日: 2017年1月

対象: Dynamics 365 (online)、Dynamics 365 (on-premises)、Dynamics CRM 2016、Dynamics CRM Online

このサンプルでは、Xrm.Page.data.process.getActivePath メソッドを使用すると返されるデータについて説明します。

要件

サンプル JavaScript ライブラリの Sdk.formOnLoad 関数は、フォームの OnLoad イベント ハンドラーとして設定する必要があります。

使用例

Xrm.Page.data.process.getActivePath メソッドは、以前のステージ、現在のアクティブ ステージ、および分岐条件や現在のフォーム データに基づいて予測される今後のステージを表すステージのコレクションを返します。 各ステージには、ステージの各ステップに関する情報を取得するのに使用できる getSteps メソッドがあります。

このサンプルでは、Xrm.Page.data.processAPI でのいくつかのメソッドの使用方法を説明します。 その目的は、この API を使用してビジネス要件を満たす方法を説明することではなく、主なプロパティ値にコードでアクセスする方法を説明することです。

Sdk.formOnLoad 関数は、Xrm.Page.data.process.getActivePath メソッドを使用して、ステージのコレクションを取得します。 次に、このサンプル コードは、コレクションの forEach メソッドを使用して、各ステージをループします。 次に、このコードは、このライブラリで定義されている Sdk.writeToConsole 関数を使用して、ステージの主要なプロパティをコンソールに書き込みます。 次にコードは、getSteps メソッドを使用して、各ステージのステップのコレクションにアクセスします。 最後に、このサンプルは、ステップ コレクションの forEach メソッドを使用して、各ステップにアクセスし、ステップの主要なプロパティをコンソールに書き込みます。

var Sdk = window.Sdk || { __namespace: true };
(function () {

 // A function to log messages while debugging only
 this.writeToConsole = function (message) {
  if (typeof console != 'undefined')
  { console.log(message); }
 };

 //Code to run in the OnLoad event 
 this.formOnLoad = function () {
  //Enumerate the stages and steps in the active path
  var activePathCollection = Xrm.Page.data.process.getActivePath();
  activePathCollection.forEach(function (stage, n) {
   Sdk.writeToConsole("Stage Index: " + n);
   Sdk.writeToConsole("Entity: " + stage.getEntityName());
   Sdk.writeToConsole("StageId: " + stage.getId());
   Sdk.writeToConsole("Status: " + stage.getStatus());
   var stageSteps = stage.getSteps();
   stageSteps.forEach(function (step, i) {
    Sdk.writeToConsole("    Step Name: " + step.getName());
    Sdk.writeToConsole("    Step Attribute: " + step.getAttribute());
    Sdk.writeToConsole("    Step Required: " + step.isRequired());
    Sdk.writeToConsole("    ---------------------------------------")
   })
   Sdk.writeToConsole("---------------------------------------")
  });
 };
}).call(Sdk);

ブラウザーでサンプルを実行すると、ブラウザーの開発者ツールを使用して、コンソールに書き込まれるテキストを表示できます。 たとえば、このサンプルを、潜在顧客エンティティ フォームの潜在顧客から営業案件への営業プロセスで実行すると、コンソールには次のように書き込まれます。

Stage Index: 0
Entity: lead
StageId: f99b4d48-7aad-456e-864a-8e7d543f7495
Status: active
    Step Name: Existing Contact?
    Step Attribute: null
    Step Required: false
    ---------------------------------------
    Step Name: Existing Account?
    Step Attribute: null
    Step Required: false
    ---------------------------------------
    Step Name: Purchase Timeframe
    Step Attribute: purchasetimeframe
    Step Required: false
    ---------------------------------------
    Step Name: Estimated Budget
    Step Attribute: budgetamount
    Step Required: false
    ---------------------------------------
    Step Name: Purchase Process
    Step Attribute: purchaseprocess
    Step Required: false
    ---------------------------------------
    Step Name: Identify Decision Maker
    Step Attribute: decisionmaker
    Step Required: false
    ---------------------------------------
    Step Name: Capture Summary
    Step Attribute: description
    Step Required: false
    ---------------------------------------
---------------------------------------
Stage Index: 1
Entity: opportunity
StageId: bfc9108c-8389-406b-9166-2c3298a2e41f
Status: inactive
    Step Name: Customer Need
    Step Attribute: customerneed
    Step Required: false
    ---------------------------------------
    Step Name: Proposed Solution
    Step Attribute: proposedsolution
    Step Required: false
    ---------------------------------------
    Step Name: Identify Stakeholders
    Step Attribute: identifycustomercontacts
    Step Required: false
    ---------------------------------------
    Step Name: Identify Competitors
    Step Attribute: identifycompetitors
    Step Required: false
    ---------------------------------------
---------------------------------------
Stage Index: 2
Entity: opportunity
StageId: 3a275c22-fc45-4e89-97fc-41e5ec578743
Status: inactive
    Step Name: Identify Sales Team
    Step Attribute: identifypursuitteam
    Step Required: false
    ---------------------------------------
    Step Name: Develop Proposal
    Step Attribute: developproposal
    Step Required: false
    ---------------------------------------
    Step Name: Complete Internal Review
    Step Attribute: completeinternalreview
    Step Required: false
    ---------------------------------------
    Step Name: Present Proposal
    Step Attribute: presentproposal
    Step Required: false
    ---------------------------------------
---------------------------------------
Stage Index: 3
Entity: opportunity
StageId: 7f5247fe-cfc3-42bc-aa77-b1d836d9b7c0
Status: inactive
    Step Name: Complete Final Proposal
    Step Attribute: completefinalproposal
    Step Required: false
    ---------------------------------------
    Step Name: Present Final Proposal
    Step Attribute: presentfinalproposal
    Step Required: false
    ---------------------------------------
    Step Name: Confirm Decision Date
    Step Attribute: finaldecisiondate
    Step Required: false
    ---------------------------------------
    Step Name: Send Thank You
    Step Attribute: sendthankyounote
    Step Required: false
    ---------------------------------------
    Step Name: File De-brief
    Step Attribute: filedebrief
    Step Required: false
    ---------------------------------------
---------------------------------------

関連項目

業務プロセス フローのスクリプトを作成する
サンプル: Xrm.Page.data.process.getEnabledProcesses

Microsoft Dynamics 365

© 2017 Microsoft. All rights reserved. 著作権