Skip to main content

Notifications

Dynamics 365 general forum
Answered

Hide Tab based on security role

Posted on by 98

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 98 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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

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

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,246 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,041 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans