Power Apps – Role Based Business Process Flow Controls
I?have implemented Role Based Business Process Flow Controls for one of our #stralto #straltoglobal project specific requirement which was not catered as a part out of the box function by Model Driven Apps. This blog is written with an intent to?assist development community.
BPF in Microsoft Model-Driven Apps (or Dynamics 365) guides users through a standard path and empowers them to understand the current status of the order/case/request in the entire Business Process, and what key process steps are completed or pending completion (please refer highlighted box).?
2. Common Business Requirements & What’s missing Out of the Box:?
In real-world applications, a single business process runs across multiple business units or teams and each ‘stage’ (refer to bulls’ eye where ‘Team Review’ is a stage in the above screenshot) in the BPF is owned or managed by a user or user group.? Current out-of-the-box BPF functionality in model-driven apps do not permit role-based progression go to ‘Next Stage’) or regression (go to ‘Previous Stage’).??
Example: Per one of Team Stralto’s project requirements, considering the scenario visible in the screenshot above - the ‘Team Review’ process stage should be available for operation (go to Next or Previous Stage) to users with the role as Team Lead and restricted to other user roles or users having access to this form. Similarly, when the process stage moves from ‘Team Review’ to ‘Manager Review’, the operation (or button) to move it to Next Stage i.e. ‘Completion’ or sending back to Team Lead’s review must be available only to users with role Manager. We were unable to find a good out-of-the-box solution to control BPF stages based on user roles.??
3. Proposed Solution?
Step 1: Restrict opening for all standard BPF buttons for Next and Previous stage movements?
To restrict the movement of BPF’s Next and Previous Stage buttons we will utilize the below JavaScript code and register it on the form load event. Every time user clicks on the Next or Previous buttons, they will get a pop-up message indicating the use of these buttons is restricted.?
领英推荐
Code Snippet:?
var Test = {};
Test.CommonScript = {?
??? handleBPFStages: function (e) {?
??????? var fc = e.getFormContext();?
??????? fc.data.process.addOnPreStageChange(Test.CommonScript.handlePreStage);?
??? },?
??? handlePreStage: function (e) {?
??????? var bpfArgs = e.getEventArgs(), entityName = Xrm.Page.data.entity.getEntityName()?
?
??????? if (bpfArgs.getDirection() === "Previous") {?
??????????? bpfArgs.preventDefault();?
??????????? var alertStrings = { confirmButtonLabel: "OK", text: "Team Stralto has customized this button click for role based? access on this BPF. You are expected to use buttons made available for your role on Ribbon to work on this Line Item.", title: "Restricted Action !!" };?
??????????? var alertOptions = { height: 150, width: 260 };?
??????????? Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);?
??????????? return;?
??????? }?
?
??????? if (bpfArgs.getDirection() === "Next") {?
??????????? bpfArgs.preventDefault();?
??????????? alertStrings = { confirmButtonLabel: "OK", text: "Team Stralto has customized this button click for role based? access on this BPF. You are expected to use buttons made available for your role on Ribbon to work on this Line Item. ", title: " Restricted Action !!" };?
??????????? alertOptions = { height: 150, width: 260 };?
??????????? Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);?
??????????? return;?
??????? }?
??? }?
};?
?
?Step 2: Create custom buttons on Ribbon?
The next step is creating two custom buttons on the form ribbon which can move business process flow from one stage to another (next stage or previous stage) and custom buttons on this ribbon can be hidden/shown based on the security role assigned to logged in user.?
4. Requesting Out of the box solution to Microsoft?
I have requested Microsoft to add this functionality on Ideas Forum and added its link below, requesting you to upvote it.
Reach out to [email protected] or [email protected] for more details
Solutions Architect/Back-end Engineer/Full-Stack Engineer/Software Developer/Enterprise Architect
2 年Thanks. Stralto Global for this. It sure was insightful