Skip to main content

Notifications

Community site session details

Community site session details

Session Id : ZuaNR9BVAWMgIQCZpV/dSt
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:
  • jbyrne1 Profile Picture
    6 on 26 Nov 2024 at 08:53:01
    Hide tab based on users security role
    That worked! Thank you so much SaiRT14.
  • Verified answer
    SaiRT14 Profile Picture
    1,966 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
     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

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

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 58

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 42 Super User 2025 Season 1

Overall leaderboard