共用方式為


範例:Xrm.Page.data.process.getActivePath

 

發行︰ 2016年11月

適用於: Dynamics CRM 2015

此範例示範當您使用 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
    ---------------------------------------
---------------------------------------

另請參閱

為商務程序流程撰寫指令碼

© 2017 Microsoft. 著作權所有,並保留一切權利。 著作權