CRM – Business Process flows and JavaScript
Microsoft describe the logic for business process flows here. As I’ve been working with business process flows recently I thought I would do a quick post explaining how to access all of the parts of a business process flow.
You use “Xrm.Page.ui.process” to access the business process flows. Then “getActiveProcess” returns an object containing the current active process.
Within this object a collections exists of the stages within the process. Then within that another collection exists containing details of each of the steps in the stage.
I’ve given an example below of how to access all of this information. Plus shown how to expand / collapse the business process flow control. And to also hide it.
Happy coding!
Xrm.Page.ui.process.setDisplayState("collapsed"); // *** Or expanded
// ** Now you see it
Xrm.Page.ui.process.setVisible(true); // ** Or false
// **getActiveProcess
var activeProcess = Xrm.Page.data.process.getActiveProcess();
alert("ID of the process: " + activeProcess.getId());
alert("Name of the process: " + activeProcess.getName());
// ** getStages
var StageCollection = activeProcess.getStages();
StageCollection.forEach(function (stage, n) {
//stage index
var stageIndex = n;
alert("Stage Index: " + stageIndex);
//stage category number
var stageCategory = stage.getCategory().getValue();
alert("Stage Category: " + stageCategory);
//stage id
var stageId = stage.getId();
alert("Stage Id:" + stageId);
//stage entity name
var stageEntityName = stage.getEntityName();
alert("Stage Entity ID: " + stageEntityName);
//stage name
var stageName = stage.getName();
alert("Stage Name :" + stageName);
//stage status
var stageStatus = stage.getStatus();
alert("Stage Status: " + stageStatus);
//steps collections
var stepsCollection = stage.getSteps();
//Number of steps
var stepsLength = stepsCollection.getLength();
alert("Steps Length: " + stepsLength);
stepsCollection.forEach(function (step, i) {
//step name
var stepName = step.getName();
alert("stepName:" + stepName);
//step attribute
var stepAttribute = step.getAttribute();
alert("stepAttribute:" + stepAttribute);
//step is required
var stepIsRequired = step.isRequired();
alert("stepIsRequired:" + stepIsRequired);
});
});
// ** Now you don't see it!
Xrm.Page.ui.process.setVisible(false); // ** Or true

Like
Report
*This post is locked for comments