Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Only show activate/deactivate button for system admins

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

  • Suggested answer
    Prajwal Bhetwal Profile Picture
    Prajwal Bhetwal 65 on at
    RE: Only show activate/deactivate button for system admins

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

  • Prajwal Bhetwal Profile Picture
    Prajwal Bhetwal 65 on at
    RE: Only show activate/deactivate button for system admins

    Hi   ,

    Thanks for the clarification.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Only show activate/deactivate button for system admins

    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.

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Only show activate/deactivate button for system admins

    Hi,

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

  • Prajwal Bhetwal Profile Picture
    Prajwal Bhetwal 65 on at
    RE: Only show activate/deactivate button for system admins

    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
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Only show activate/deactivate button for system admins

    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
    Prajwal Bhetwal 65 on at
    RE: Only show activate/deactivate button for system admins

    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
    M.Anas Profile Picture
    M.Anas 35 on at
    RE: Only show activate/deactivate button for system admins

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans