In this blog, we will look at how we can display different business process flow based on user security role in D365 CE.

Use Case:

In my example, I have two Business Process Flow on Opportunity entity.

  • Opportunity Sales Process 
  • Manager Process 

 

Users with a “Custom Project Management Role” security role can only see Manager Process Business Process Flow. 

Implementation:

var formCustomizations = {

    displaybpf: function (executionContext) {

        var formContext = executionContext.getFormContext();
        var managerRoleId = "520359B5-FF61-EB11-A812-00224806B6E3"; //GUID of Manager Role
        var userSettings = Xrm.Utility.getGlobalContext().userSettings;
        var userRoles = userSettings.securityRoles;
        var userHasRole = false;

        userRoles.forEach(roles => {
            if (roles.toLowerCase() === managerRoleId.toLowerCase()) {
                userHasRole = true;
                return;
            }
        });

        if (userHasRole === true) {
            formContext.data.process.setActiveProcess("b7363263-2265-eb11-a812-000d3a3759c1"); //Pass the GUID of BPF to show when user has security role
        }
        else {
            formContext.data.process.setActiveProcess("3e8ebee6-a2bc-4451-9c5f-b146b085413a"); //Pass the GUID of other BPF to show when user does not have security role
        }
    }
}
  • register an Event On Form Load, as shown below:

Display different Business Process Flow based on user security role in D365 CE /PowerApps_d3Display different Business Process Flow based on user security role in D365 CE /PowerApps_d3_02

Testing:

User with Manger Role:

Display different Business Process Flow based on user security role in D365 CE /PowerApps_sed_03

User without Manager Role:

Display different Business Process Flow based on user security role in D365 CE /PowerApps_sed_04

Note:

  1. Make sure you have added both the Business Process Flow in the Model-driven app.

Display different Business Process Flow based on user security role in D365 CE /PowerApps_d3_05