Microsoft Power Platform - Show/hide ribbon buttons on field values & roles
Team Stralto implemented ribbon customization per business requirement where expectation was to show or hide of custom buttons on ribbon based on value of a particular field and/or for a certain security role of the user.??
We did find similar open questions on stack overflow and other dynamics/power apps forums but were unable to search a decent workable solution. This endeavor made us include the use case in our tech. blog and it is written with an intent to assist development community.
Developers can quickly achieve this type of customization activity in model driven apps with JavaScript. Sample with code snippet:?
function showAcceptButton(primaryControl) {
globalFormContext = primaryControl;
var value = globalFormContext.getAttribute('ex_paymentstatus').getValue();
var roleIsMatchingFlag = false;
// debugger;
var currentUserRoles = Xrm.Page.context.getUserRoles();
for (var i = 0; i < currentUserRoles.length; i++) {
var userRoleId = currentUserRoles[i];
var userRoleName = GetRoleName(userRoleId);
if (value == 111111111 && ((userRoleName === "System Administrator")) {
roleIsMatchingFlag = true;
break;
}
}
return roleIsMatchingFlag;
}
}
The ribbon button “Accept” should be visible to only when the value in the “Payment Status” field is “Completed” and for users with the “System Administrator” role.?
Note: Here, the value '111111111' represents the status 'Completed'.?
The above JavaScript function checks for all the roles user has; if the desired security role is found, it will return the value 'True'. It will also check for the Payment status and if the value matches, it will return True and show or hide the button.?
?Reach out to [email protected] or [email protected] for more details.
Jr. Software Engineer at Technomile
2 年Congratulations Praful Shelke
Consultant
2 年Excellent work ??
DevOps Engineer at Lentra
2 年Congratulations?? bro??
Microsoft Dynamics 365 CRM Developer | 3+ Years of Expertise in Customization, Configuration & Integration | Passionate About Automating Workflows Enhancing Customer Engagement & Driving Digital Transformation for Growth
2 年Great job Praful Shelke .... Kudos to Stralto Global for this initiative....??????
Consultant at Stralto
2 年Congratulations Praful..keep up the good work.