Hi,
To conditionally show or hide the Edit button in a model-driven app based on user roles and field values, you’ll need to use Ribbon Workbench along with JavaScript. Here's a general approach to get started:
Use Ribbon Workbench: This tool allows you to customize command bar buttons. You can define display rules and enable rules based on JavaScript functions.
Create a JavaScript Web Resource: Write a function that checks:
status
is marked as complete.Example snippet:
function shouldShowEditButton(formContext) {
var status = formContext.getAttribute("status").getValue();
var userRoles = Xrm.Utility.getGlobalContext().userSettings.roles;
var hasRole = userRoles.some(function(role) {
return role.name === "YourRoleName";
});
return !(hasRole && status === "Complete");
}
Attach the Function in Ribbon Workbench: Use this function in a Display Rule or Enable Rule for the Edit button.
Publish and Test: After publishing the changes, test the behavior in your app to ensure the button visibility aligns with your criteria.
This setup gives you flexibility and control over UI behavior based on business logic.
Please verify if this helps you move forward.
Thanks and best regards,\
Daniele\
Note: This response was prepared with support from Copilot to ensure clarity and completeness.
Hamza H
1,786
Muhammad Shahzad Sh...
1,132
Most Valuable Professional
Abhilash Warrier
351
Super User 2025 Season 2