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)

Ribbon workbench - Activate Button on account record

(0) ShareShare
ReportReport
Posted on by 375

Hello,

I have successfully implemented a solution using the Ribbon Workbench to hide/show certain ribbon buttons on forms and views based off of a users security role.  I had to add an additional role to ONLY the command which displays the Activate button on the Account form/view.  The button will display now but when you click it, nothing happens.  The other roles which were part of the initial successful implementation still function as they should.  I am not sure if this is a Ribbon Workbench issue or a security role setting for this role.  Here is the code being used and the ribbon workbench setting:

1581.Account_5F00_Command.png

2844.Account_5F00_EnableRule.png

Here is the script being used.  In this scenario, "role4" is the issue.  The account entity security settings for role4 are below. 

function getUserRoles() {
 
        var roleid = Xrm.Page.context.getUserRoles();
        var name;
        var showButton = false;
        for (var i = 0; i < roleid.length; i++) {
            var roleID = roleid[i];
            var RoleName = getRoleName(roleID);
            if (RoleName == '[role1]' || RoleName == '[role2]' || RoleName == '[role3]' || RoleName == '[role4]') {
                showButton = true;
                break;
            }
        }
        return showButton;
}

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: ' + OdataURL);
            }
        });
        return roleName;
}


Security role settings; Account entity for role4:

2287.Account_5F00_R4_5F00_Security.png

*This post is locked for comments

I have the same question (0)
  • Arun Vinoth Profile Picture
    11,615 Moderator on at

    Did you try to debug? Any errors in browser console?

  • Community Member Profile Picture
    on at

    Hi Ruger,

    Please try below code in getUserRoles() function (within for loop):

    var roleID = roleid[i];

    roleID = roleID.replace("}","");

    roleID = roleID.replace("{","");

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Try with this -

          function getUserRoles() {
                var roleid = Xrm.Page.context.getUserRoles();
                var name;
                var showButton = false;
                for (var i = 0; i < roleid.length; i++) {
                    var roleID = roleid[i];
                    var RoleName = getRoleName(roleID);
                    if (RoleName == '[role1]' || RoleName == '[role2]' || RoleName == '[role3]' || RoleName == '[role4]') {
                        showButton = true;
                        break;
                    }
                }
                return showButton;
            }
    
    
            function getRoleName(roleId) {
                var serverUrl = location.protocol + "//" + location.host + "/" + Xrm.Page.context.getOrgUniqueName();
                var odataSelect = 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: odataSelect,
                        beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
                        success: function (data, textStatus, XmlHttpRequest) {
                            roleName = data.d.results[0].Name;
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + textStatus + errorThrown + odataSelect); }
                    }
                                );
                return roleName;
            }
    


  • RugerSR762 Profile Picture
    375 on at

    Goutam - thank you.  Your suggestion worked!

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