Sample: 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。 保留所有权利。 版权