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 Platform Community / Forums / Power Apps / Hide tab based on user...
Power Apps
Unanswered

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,990 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 757 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 322 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 209 Super User 2025 Season 2

Last 30 days Overall leaderboard