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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Hide /Show a button based on Security Role ( Using Ribbonworkbench ) ?

(1) ShareShare
ReportReport
Posted on by 1,401

Hello All,

I am using Following Javascript  to get  current role of User .  

How should i enable and disable a button using below  Js in Ribbon workbench .

Can anyone help me on this ?   Thank you :)

function getUerRoles()

{

var roleid = Xrm.Page.context.getUserRoles();
var name;
for (var i = 0; i < roleid.length; i++) {
var roleID = roleid[i];
var RoleName = getRoleName(roleID);
if (RoleName == 'System Administrator') {
return true;

   }
else
   {
return false;
}

}


}
function getRoleName(roleID) {


  var serverUrl = Xrm.Page.context.getClientUrl();
var OdataURL = serverUrl + "/XRMServices/2011/OrganizationData.svc" + "/" + "RoleSet?$filter=RoleId eq guid'" + roleID + "'";
var roleName = null;

$.ajax({
type: "GET",
async: false,
contentType: "application/json; charset=utf-8", datatype: "json",
url: OdataURL,
beforeSend:
function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success:
function (data, textStatus, XmlHttpRequest) {
var result = data.d;
roleName = result.results[0].Name;
},
error:
function (XmlHttpRequest, textStatus, errorThrown) {
// alert('OData Select Failed: ' + odataSelect);
}
});
return roleName;

}

*This post is locked for comments

I have the same question (0)
  • Rajkumar Rajaraman Profile Picture
    on at

    Refer this blog:

    inogic.com/.../adding-custom-button-on-security-area-in-dynamics-crm-2015

  • Mclare Profile Picture
    1,401 on at

    Hello Rajkumar , thank you .

    This is not actually my requirement . I wanted to disable or enable a button according to security role in entity form :)

  • Verified answer
    Mclare Profile Picture
    1,401 on at

    I have got t :) Thank you .

  • Community Member Profile Picture
    on at

    Can you please share the solution you've found?

  • Vineet  Mehra Profile Picture
    75 on at

    Hi Mclare,

    Your button was on HomePageGrid of the entity or Form ?

    If it is on HomePageGrid , can you please share the solution. I am able to achieve it on form but not on HomePageGrid.

    Thanks!

  • Community Member Profile Picture
    on at

    hi MClare,

    This is the same issue i am facing. can you please share how you solve this issue

    Thanks in Advance

  • Community Member Profile Picture
    on at

    can u please explain how u have done enabling button to particular roles

  • Mclare Profile Picture
    1,401 on at

    Hi all , I have done this through javascript . based on security role , return true /false - added this function as enable rule in ribbon button .

  • Community Member Profile Picture
    on at

    Yes, after doing much R&D i got the answer, as Mclare given the code above is for checking roles and as my requirement is to enable reopen opportunity button only System Admin that code fits for my requirement just create web resource add that code in it and then in ribbon workbench Choose the solution the contains the Form-> Right Click Enable Rule→  Click Add New -> Choose “Custom JavaScript Rule” Populate function name in the FunctionName field  and choose the JS library in Library field -> Associate the Rule with a Command -> Associate the Command with the button -> Publish the Ribbon changes ...

    for more detail you can refer below links :

    https://community.dynamics.com/crm/b/aaronbellscrmblog/archive/2016/07/11/how-to-disable-a-crm-2016-ribbon-button-based-on-form-name

    https://garethtuckercrm.com/2013/11/25/dynamically-disable-ribbon-buttons-in-dynamics-crm/

  • Suggested answer
    Goutham A Profile Picture
    2 on at

    use the same logic as ribbon enable rules for homepage grid as well. It should work

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans