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 :
Power Apps - Building Power Apps
Answered

Hide tab based on users security role

(0) ShareShare
ReportReport
Posted on by 6
Hi, 
 
I have a model driven power app in which I need to hide a certain tab if the user has a certain security role. I followed the instructions here to do this via javascript.
 
I now have the problem that the tab is always hidden, regardless of the users security role. My javascript is;
 
function onLoad(execCtx) {
    const formCtx = execCtx.getFormContext();
    
    const roleName = "Project User";
    const isUser = Xrm.Utility.getGlobalContext().userSettings.roles.get(r => r.name == roleName);

    if (isUser) {
        formCtx.ui.tabs.get("tab_6").setVisible(false);
    }
}
 
Can anyone help me with this?
Categories:
I have the same question (0)
  • Verified answer
    SaiRT14 Profile Picture
    1,988 Super User 2025 Season 2 on at
    Hide tab based on users security role
    pls try the following:
     
    function onLoad(execCtx) {
        const formCtx = execCtx.getFormContext();
        const globalContext = Xrm.Utility.getGlobalContext();
        const roleName = "Project User"; // Replace with your exact role name
        const userRoles = globalContext.userSettings.roles;
        let hasRole = false;
        // Iterate through the user's roles to check for the specified role
        userRoles.forEach(function (role) {
            if (role.name === roleName) {
                hasRole = true;
            }
        });
        // Hide the tab if the user has the specified role
        if (hasRole) {
            formCtx.ui.tabs.get("tab_6").setVisible(false);
        }
    }
     
    it should fix your issue
     
  • jbyrne1 Profile Picture
    6 on at
    Hide tab based on users security role
    That worked! Thank you so much SaiRT14.

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…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 629 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 397 Super User 2025 Season 2

#3
wolenberg_ Profile Picture

wolenberg_ 232 Moderator

Last 30 days Overall leaderboard