3

We have a certain requirement in CRM 2015 in which we need to restrict backward movement in Business Process Flow for Non-S/S Admin users.

I iterated through Client API’s (including scripting for Upgrade 1) but I didn’t find any API for achieving using any of the exposed method. So, finally I wrote custom code for this by hijacking the backward movement of the Business Process Flow and prompting user that this is the restricted move for Non-S/S admin users.

However, this is an unsupported change and I see this won’t be an issue as long as DOM ids are same (since on a quick look I found DOM Ids are same in 2013, 2015 and 2015 Rollup1 for BPF).

function restrictBPFPreviousMove() {
    var originalPreviousStageHandler = $("#stageBackActionContainer").data("events")["click"][0].handler;

    $("#stageBackActionContainer").unbind("click");
    $("#stageBackActionContainer").click(function (e) {
        alert("Restricted Back Move!");
    });
}

However, I was wondering if there is any alternative (supported) to this approach?

jasonscript
  • 6,039
  • 3
  • 28
  • 43
Kunal Goel
  • 3,357
  • 1
  • 14
  • 20

2 Answers2

4

CRM 2015 has events for stage selection and change that can be handled.

Business Process Flow control events

Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update provides two events for user interaction with the business process flow control. OnStageChange Occurs when a stage changes. More information: OnStageChange event. OnStageSelected Occurs when a stage is selected. More information: OnStageSelected event. There is no UI to register scripts for these events. Use the following methods in functions registered in the form OnLoad event to register your functions for these events.

Xrm.Page.data.process.addOnStageChange

Xrm.Page.data.process.addOnStageSelected

Xrm.Page.data.process.removeOnStageChange

Xrm.Page.data.process.removeOnStageSelected

You still have to check the role of the user by hand (retrieve systemuser, retrieve role, mix & match)

Alex
  • 23,004
  • 4
  • 39
  • 73
0

First get all the Stages guid with Xrm.Page.data.process.getActiveProcess().getStages() and store it in var as

var stage1= "efe2a761-9f5c-492c-9843-54decc2ab76a";
var stage2= "dddddd34-9f5c-492c-9843-54decc2ab76a";
var stage3= "abcdef12-9f5c-492c-9843-54decc2ab76a";

Next add a Event Handler using Xrm.Page.data.process.addOnStageChange() that checks for the Active stage guid as

var currentStageId = Xrm.Page.data.process.getActiveStage().getId();

then you try moving the stage using either of the following

Xrm.Page.data.process.moveNext();
Xrm.Page.data.process.movePrevious();
Xrm.Page.data.process.setActiveStage();
Vinod Srivastav
  • 3,644
  • 1
  • 27
  • 40