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 365 | Integration, Dataverse...
Answered

Only show activate/deactivate button for system admins

(0) ShareShare
ReportReport
Posted on by 65

Hi,

I want to hide this activate/deactivate button for all users except system admins. How can I achieve this using the ribbon workbench? 

pastedimage1663556677287v1.png

Thanks,

Prajwal

I have the same question (0)
  • Suggested answer
    M.Anas Profile Picture
    35 on at

    Hello,

    Prajwal Bhetwal

    You have to create  java script and add it into ribbon work bench enable rule .

    https://d365demystified.com/2021/02/14/show-custom-ribbon-button-based-on-security-role-of-the-logged-in-user-in-dynamics-365-ribbon-workbench-in-xrmtoolbox/

    Hope this link will help you.

  • Prajwal Bhetwal Profile Picture
    65 on at

    This solution works OK if we are dealing with only custom security roles. We have a problem here if we need to check the logged-in user roles with any out-of-box security roles(System Administrator). The GUID of out-of-box roles are different in a different instance. So, the JS will not work.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Prajwal Bhetwal,

    If so, you could try to check the security name other than id. Please use the JS in the following blog to replace it:

    Dynamics 365: Check if the current user has specific role - WareTec

  • Prajwal Bhetwal Profile Picture
    65 on at

    Hi  

    That didn't work either. 

    Here's what I did:

    1. Added the JS as a web resource in the environment and published the web resource.

    pastedimage1663656911799v1.png

    2. Created a new solution in environment and added an account entity with no data in it.

    3. Loaded that solution in ribbon workbench

    4. Selected the Deactivate button and added an enable rule

    pastedimage1663657015609v2.png

    5. Published the solution

    6. Tested using an account that is not a system admin user

    What am I missing?

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    Display name of the system admin role should be "System Administrator" so compare it with that, you can also debug your code.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Prajwal Bhetwal,

    Its role name should be "System Administrator". So try the following code:

    function hasCurrentUserRole(roleName){
      let hasRole = false;
      let roles = Xrm.Utility.getGlobalContext().userSettings.roles;
      roles.forEach(x => {
                    if (x.name === "System Administrator") {
                        hasRole = true;
                        return;
                    }
                   });
       return hasRole;
    }

    And the rule should be tied to the button command.

    Steps:

    1. Right click the ‘DEACTIVATE’ button and open the 'Customise Command':

    pastedimage1663660557220v1.png

    2. Then add your custom enable rule to command:

    pastedimage1663660790606v2.png

    3. Finally, publish your solution.

  • Prajwal Bhetwal Profile Picture
    65 on at

    Hi   ,

    Thanks for the clarification.

  • Suggested answer
    Prajwal Bhetwal Profile Picture
    65 on at

    It's working now. Thank you, Steve !!

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 51 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans