web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Hide Tab based on security role

(0) ShareShare
ReportReport
Posted on by 27

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,

I have the same question (0)
  • Verified answer
    XM-22040801-0 Profile Picture
    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

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

    Thank you Xavier Monin

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
#ManoVerse Profile Picture

#ManoVerse 101

#2
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 66 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans