web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

ribbon button and security roles

(0) ShareShare
ReportReport
Posted on by 2,665

HI,

I've been working on hiding a ribbon button based on the security role. I've seen many articles explaining how to do this with javascript function and an enable rule. For example, this link:

Can we create enable rules for multiple security roles? When I pass the parameter(security role name) to the function.. only those users with the security role are able to see the button. Even System Admins cannot see the button. How do I let the admins see the button always along with the role I am passing?

Thanks for any help. 

*This post is locked for comments

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at
    RE: ribbon button and security roles

    Hello,

    You need to develop some kind of configuration where you can configure which security roles are allows for particular form button or you could have security role name in some of the field in entity form and then you need to setup a custom java script function which will read the configuration or the value of the entity field based on that it will return true or false from your method.

    And now you need to use this custom js function in your button for enable rule.

    Thanks

  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at
    RE: ribbon button and security roles

    Hello,

    You can try to follow the instructions from the below mentioned link:-

    rajeevpentyala.wordpress.com/.../check-user-role-in-crm-2011-using-jscript

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: ribbon button and security roles

    Roxanna,

    Can..

    But again, you need to use javascript.

    Use the passing parameter in the ribbon workbench and your JS must be able to capture it.

    If you need something easier, you can use privilege rule, you can create new entity a dummy one just to manipulate it.

    Thanks

  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: ribbon button and security roles

    Thanks guys for suggestions.

    I've followed the link that RajKumar suggested and able to implement. But it lets only the role that I specify to see the button. Even Admins cannot see the button. Should I have to implement the same thing for 'Administrators' role as well?

    Thank you.

  • Rajkumar Rajaraman Profile Picture
    on at
    RE: ribbon button and security roles

    You should provide your condition from the above link:

    if(UserHasRole(‘System Administrator’)){

    alert(“Current logged-in user is  System Adminstrator”);

    return true;//Enable button using ribbon workbench

    }

    else

    {

    return false;//Disable button

    }

  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: ribbon button and security roles

    Thanks Rajkumar. But if I want to add another security role along with 'System Administrator'... do I have to create another enable rule in the ribbon workbench with the "Value" being 'anotherSecurityRole'?

  • Verified answer
    anilambadan Profile Picture
    1,160 on at
    RE: ribbon button and security roles

    Hi

    if(isUserInRole (‘System Administrator’, 'userid') || isUserInRole ('another role','userid')){

    return true;//Enable button using ribbon workbench

    }

    else

    {

    return false;//Disable button

    }

    isUserInRole = function(roleName, userId)

    {

    /// <summary>

    /// Returns true of the current user has the given security role

    /// </summary>

    if (userId == null)

    {

    userId = Xrm.Page.context.getUserId();

    }

    var roleFound = false;

    var serverUrl = Xrm.Page.context.getClientUrl();

    var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";

    oDataEndpointUrl += "SystemUserSet(guid'" + userId + "')/systemuserroles_association?$select=RoleId&$filter=Name eq '" + roleName + "'";

    $.ajax({

    type: "GET",

    async: false,

    contentType: "application/json; charset=utf-8",

    dataType: "json",

    url: oDataEndpointUrl,

    success: function(data)

    {

    if (data != null && data.d.results.length > 0)

    {

    roleFound = true;

    }

    },

    error: function(request, status, error)

    {

    alert(request.responseText + " : " + status + " : " + error);

    }

    });

    return roleFound;

    }

    thanks

    Anil

  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: ribbon button and security roles

    Thanks for the code. Its not working for me. Please guide me.. What I did was.. I entered the two security role's names and userId(null) as the parameters in the 'Enable Rule'. And the function name as 'isUserInRole'.

    What am I doing wrong? Please guide me.

    7167.Capture.PNG

    and the same function:

    if(isUserInRole (roleName, userId) || isUserInRole (roleName1,userId)){
    
    return true;//Enable button using ribbon workbench
    }
    else
    {
    return false;//Disable button
    }
    isUserInRole = function(roleName, userId)
    {

    Thank you.


  • Suggested answer
    ScottDurow Profile Picture
    21 on at
    RE: ribbon button and security roles

    Instead of using Javascript, there is a much easier and supported route using ths technique I describe here - ribbonworkbench.uservoice.com/.../76681-hide-a-standard-out-of-the-box-button-based-on-a

    You have to simply nominate a privileges per button.

    Hope this helps,

  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: ribbon button and security roles

    Thanks Scott. You are awesome. :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans