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 / How do i hide a comman...
Power Apps
Unanswered

How do i hide a command bar button based on the users security role

(0) ShareShare
ReportReport
Posted on by 8
Hi, 

I am trying to hide two buttons from the command bar in my model driven app. The buttons should be hidden or shown based on the logged in users role. 
If the user has the "Manager" role the two buttons should be show. Otherwise the buttons should be hidden. The "Manager role" can see all project entities across the users, but only have read permissions on the project entity. Because of this i just checked of the user have create permission on the project entity. If not, then show the button. 

Here is my power fx code, set in the visibility condition bar: 

If(DatasourceInfo(projects; DataSourceInfo.CreatePermission); false; true)

I have tried different variations but i cant get it working. Not mather what, all of my users can see the buttons.  
Categories:
I have the same question (0)
  • Nirav Raval (Akira28) Profile Picture
    153 Moderator on at
    How do i hide a command bar button based on the users security role
    Hi @SR-10021045-0
     
    >> Use this steps might resolve -
    1) Instead of DatasourceInfo, use a direct check against the user's role.
    2) Fetch the Securityroles table to verify if the logged-in user has the "Manager" role.
    3) Set the button’s Visible property accordingly.

    Modify the Visible property of your buttons with this Power Fx formula:
     
    If(
        LookUp(
            SecurityRoles,
            Name = "Manager" && User().Email in Users.Email
        ),
        true,
        false
    )
     
    If this post solved your issue, clicking 'Does this answer your question' will help others discover the solution and close the topic. If you found it helpful, a Like would be awesome!

    Regards,
    Nirav J Raval (Akira28) 🤞
  • YS-15091406-0 Profile Picture
    2 on at
    How do i hide a command bar button based on the users security role
    Sorry this is not how the security role table works. That Security Role table lists the security roles (Basic User, System Administrator, Workspace Contributor, etc) and their features such as date created,  is it customisable, inherited, and so on NOT the list of users in the organisation and their access privileges. Your response is same as I got when I typed into a chatbot. Please share verified answers instead of getting stars as a moderator for pasting chatbot stuff. It does not help as I come to forums seeking real feedback because I am new and need assistance from experienced builders.
     
  • Suggested answer
    Youssef_Arouay Profile Picture
    176 on at
    How do i hide a command bar button based on the users security role
    Hi,

    To control button visibility in a model-driven app using security roles, DataSourceInfo() will not work the way you expect.

    DataSourceInfo() checks permissions on the table, but Model-Driven Apps do not evaluate permissions this way inside command bar visibility rules. That’s why all users still see the buttons — the condition is never evaluated correctly.

    Try using just : 
     
              => User().HasRole("Manager")
     
  • Suggested answer
    QuentinDURIEZ Profile Picture
    547 Moderator on at
    How do i hide a command bar button based on the users security role
    Hi,

    I never succeeded to hide a command using the user security roles, event if you manage to get the user roles you will experience delegation, so sometimes it will work, sometimes no.

    The only way is creating the command the old way with Ribbon Workbench and a custom Enable rule

    Regards,

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

Coming soon: forum hierarchy changes

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 819 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 308 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 222 Super User 2025 Season 2

Last 30 days Overall leaderboard