Skip to main content

Notifications

Community site session details
Power Apps - Building Power Apps
Answered

Hide tab based on users security role

Like (0) ShareShare
ReportReport
Posted on 25 Nov 2024 20:17:10 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:
  • Verified answer
    SaiRT14 Profile Picture
    1,983 Super User 2025 Season 1 on 25 Nov 2024 at 21:51:37
    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
     

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 413 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 193

#3
stampcoin Profile Picture

stampcoin 149

Overall leaderboard
Loading complete