Get active Stage
If you need to get the name or Id of the current stage, follow code below;
var activeStage = Xrm.Page.data.process.getActiveStage();
alert(activeStage.getId());
alert(activeStage.getName());
To hide the active business Process Flow
Xrm.Page.ui.process.setVisible(false); //Or true
To expand or collapse the active business process flow
Xrm.Page.ui.process.setDisplayState("collapsed"); // Or expanded
Move to next stage in the business process
You can use the moveNext method to navigate to the next stage in the business process. As shown below
var activeProcess = Xrm.Page.data.process.getActiveProcess;
if (activeProcess != null) {
Xrm.Page.data.process.moveNext(function (result) {
if (result == "success") {
// ** Code for success goes here
alert("Worked");
} else {
// ** Code for failure goes here
alert("Had an Issue");
};
});
};
Move to the previous stage in the business process
You can use the movePrevious method to navigate to the next stage in the business process. As shown below;
var activeProcess = Xrm.Page.data.process.getActiveProcess;
if (activeProcess != null) {
Xrm.Page.data.process.movePrevious(function (result) {
if (result == "success") {
// ** Code for success goes here
alert("Worked");
} else {
// ** Code for failure goes here
alert("Had an Issue");
};
});
};
Add a function triggered whenever a user selects a stage
You can define an “On Stage Selected” function that will be triggered whenever a stage is clicked by the user.
//adding a named function on stage selection
Xrm.Page.data.process.addOnStageSelected(StageSelected);
function StageSelected() {
alert("Stage selected!");
}
OR you could use the following syntax
Xrm.Page.data.process.addOnStageSelected(function () {
Alert("Stage selected");
});
Set Active Stage
You can set the active stage, by using the ID of the stage. (Obviously, your ID will be different from the one shown!)
var GUID = "15322A8F-67B8-47FB-8763-13A28686C29D";
Xrm.Page.data.process.setActiveStage(GUID, function(result) {
if(result == "success") {alert("Success");} else {alert("Invalid");}
});
No comments:
Post a Comment