Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Hide Tab based on security role

Posted on by 100

Hi everyone,

Could anyone please share sample java script code to hide a tab based on the current users custom security role? E.g. if the security role name is "Administrator", hide a specific tab.

Best regards,

  • Ami K Profile Picture
    Ami K 100 on at
    RE: Hide Tab based on security role

    Thank you Xavier Monin

  • Verified answer
    XM-22040801-0 Profile Picture
    XM-22040801-0 11 on at
    RE: Hide Tab based on security role

    Hi,

    You can use this javascript:

    /* Hide "mytab" tab if the user is an administrator
     * Register this event handler on form load.
     * Check the "Pass execution context as first parameter" checkbox.
    */
    function onLoad(execCtx) {
        const formCtx = execCtx.getFormContext();
        
        const roleName = "System Administrator";
        const isAdmin = Xrm.Utility.getGlobalContext().userSettings.roles.get(r => r.name == roleName);
    
        if (isAdmin) {
            formCtx.ui.tabs.get("mytab").setVisible(false);
        }
    }

    To learn more: learn.microsoft.com/.../usersettings

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,928 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans