Saturday, August 23, 2025

Hide And Show The Dynamics 365 CRM Button Based On Logged In User Security Roles

 In this post I am going to explain how you will hide and show the Ribbon/Command buttons based on logged in user security rule.

I have one Delete button on one Custom entity(Employee). I have to hide this button based on logged in user security roles, for it I used the Enable Rule.

Create the java script with function as below.

function HideLeadQualifyButtonBasedOnRoles()
{
    let hasRole = false;
    let roles = Xrm.Utility.getGlobalContext().userSettings.roles;
    roles.forEach(x =>
  {
        if (x.name === "Area Manager" || x.name === "Sales Manager")
{
            hasRole = true;
            return;
        }
    });
    if (hasRole === true) {
        return true;
    } else {
        return false;
    }
}



1. Open your solution into your ribbon workbench => Select your button => click on Enable Rule => Add Step


2. Select the CustomRule and add the Function Name and Web Resource.


3. Publish your changes.


No comments:

Post a Comment

Hide And Show The Dynamics 365 CRM Button Based On Logged In User Security Roles

 In this post I am going to explain how you will hide and show the Ribbon/Command buttons based on logged in user security rule. I have one ...