JavaScript, add code to business process flows

Recently I needed to add code when stages in my business process flow were selected or changed. This is easy to do.

Simply register the functions you wish to be called as users change or select stages in your onload event.

Sample code is shown below;

function OnLoad() {
  // *** Whenever the stage changes trigger an onchange function
  Xrm.Page.data.process.addOnStageChange(stageOnChange);
  // To remove the function if required ….. Xrm.Page.data.process.removeOnStageChange(stageOnChange);

  // *** Whenever a stage is selected trigger a function
  Xrm.Page.data.process.addOnStageSelected(stageSelected);
  // To remove the function is required …. Xrm.Page.data.process.removeOnStageSelected(stageSelected);
}

function stageOnChange() {
  stage = Xrm.Page.data.process.getActiveStage();
  alert("The stage has changed to " + stage.getName());
}

function stageSelected() {
  stage = Xrm.Page.data.process.getSelectedStage();
  alert("Selected stage is " + stage.getName());
}

This is a short but hopefully useful post.
J

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