Business Process Flows – JavaScript (part 2)

Recently I published a post describing how to access the various components of a business process flow, including the currently active process flow, details about the stages in the process and also the steps within the stage.

Here I will build upon that post and look at what actions can be performed on a business process flow.

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 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 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 to 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");
 }
});

Happy coding!,

2 thoughts on “Business Process Flows – JavaScript (part 2)

  1. Pingback: Happy New Year – Pop Pickers | Microsoft Dynamics CRM and Unified Service Desk

  2. Pingback: New Year’s Eve 2016 | Microsoft Dynamics CRM and Unified Service Desk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s