Udostępnij za pośrednictwem


Sample: Xrm.Page.data.process.getActivePath

 

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

This sample demonstrates the data returned when you use the Xrm.Page.data.process.getActivePath method.

Requirements

The Sdk.formOnLoad function in the sample JavaScript library must be set as the OnLoad event handler for a form.

Demonstrates

The Xrm.Page.data.process.getActivePath method returns a collection of stages that represent any previous stages, the current active stage, and the predicted future stages taking into account the branching conditions and the current form data. Each stage has a getSteps method that you can use to retrieve information about each step in the stage.

This sample illustrates the use of some of the methods in the Xrm.Page.data.process API. It doesn’t represent using this API to meet a business requirement; it’s only intended to demonstrate how the key property values can be accessed in code.

Example

The Sdk.formOnLoad function uses the Xrm.Page.data.process.getActivePath method to retrieve a collection of stages. Then, the sample code uses the forEach method of the collection to loop through each stage. The code then writes key properties of the stage to the console using the Sdk.writeToConsole function defined in this library. The code then accesses a collection of steps for each stage using the getSteps method. Finally, the sample uses the forEach method of the steps collection to access each step and write key properties of the step to the console.

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);

When the sample runs in the browser, you can use the developer tools of the browser to view the text written to the console. For example, when this sample is run in the Lead entity form with the Lead to Opportunity Sales Process, the following is written to the console:

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
    ---------------------------------------
---------------------------------------

See Also

Write scripts for business process flows
Sample: Xrm.Page.data.process.getEnabledProcesses

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright