web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to check if the cu...
Power Apps
Answered

How to check if the current user has a specific security role?

(0) ShareShare
ReportReport
Posted on by 60
I have build an canvas Power App on top of dataverse tables. I created 2 security roles. Security role "Operator", and the other "Manager". I would like to hide some dropdown control if the current user dont have the security role "Manager". How to do this in an canvas app?
Categories:
I have the same question (0)
  • Suggested answer
    Assisted by AI
    MMcCloud Profile Picture
    393 Moderator on at
    Good Morning,
     
    Security roles are stored in your Security Roles table so to use them as parameters for component visibility or mode you need to expose that table so you need to create a relationship between the users and roles.
     
    So basically go into Power Apps Studio for your app and add the systemuserroles and roles tables as data sources for your app.
     
    Then check the users roles using the User() function to get their email filter like such
    Filter(
    'systemuserroles', 'SystemUser'.'PrimaryEmail' = User().Email)
     
    Then we set the visible property of the dropdown based off the filter above
     
    If(
    CountRows(
    Filter(
    'systemuserroles',
    'SystemUser'.'PrimaryEmail' = User().Email &&
    'Role'.Name = "Manager"
    )
    ) > 0,
    true,
    false
    )
     
     
    So in short we add the two tables create a filter for the relationship then do a count of the rows in that filtered relationship to see if there are any entries [does the user exist with the manager role] then make the item visible or remove it from view.
     
    If this answers your question, please select it as the solution if not feel free to reply I will try to continue assisting have a good day!
  • HAKHBIZ Profile Picture
    60 on at
    Are you sure the name of the tables are "systemuserroles" and "roles"? I did find only the table "Security Roles".

  • Suggested answer
    whitebeard Profile Picture
    135 on at
    Hi @HAKHBIZ,
    To hide a control based on a specific Dataverse security role, you need to access the relationship between the Users table and the Security Roles table.
     
    Here is the step-by-step solution:
     
    1. Add Data Sources
     
    First, add the following two tables to your Canvas App data sources:
    Users (systemuser)
    Security Roles (role)
     
    2. Store User Roles (On App Start)
    It is best practice to fetch the current user's roles when the app starts so you don't query the database constantly.
    Go to the App object in the Tree View, find the OnStart property, and paste this code:
     
    // 1. Get the current logged-in user record
    Set(
        gblCurrentUser, 
        LookUp(Users, 'Primary Email' = User().Email)
    );
     
    // 2. Collect all roles assigned to this user into a collection
    // Note: 'Security Roles (systemuserroles_association)' is the standard relationship name
    ClearCollect(
        colUserRoles, 
        gblCurrentUser.'Security Roles (systemuserroles_association)'
    );
     
     
    Note: Run the OnStart property once manually by right-clicking the App object -> Run OnStart so the collection populates for testing.)
     
    3. Configure the Control
    Select the Dropdown control you want to hide. Go to its Visible property and use this formula:
     
    "Manager" in colUserRoles.Name
     
     
    How it works:
     
    The code looks up the user in the Dataverse Users table matching their email.
    It then navigates the systemuserroles_association relationship to get a list of all roles assigned to that user.
    The Visible property simply checks if the string "Manager" exists in that list of role names.
     
    Video Resource
     
    If you prefer a visual walkthrough, this video covers the exact steps for fetching and checking security roles:
     
     
    Hope this helps!
     
  • HAKHBIZ Profile Picture
    60 on at
    With accountA where I builded the app this is working. I see some security roles in colUserRoles. I shared the app with accountB and give it some security roles. In the app colUserRoles is empty. Did I miss something? I assigned the security roles by the share button.


    Update
    It looks like variable gblCurrentUser is empty for user B. How to fix this? I expect that when I share the app with someone and assign the security role, that this person can use the app with some security trimmed functionality.


  • Verified answer
    whitebeard Profile Picture
    135 on at
    Could you please confirm if the account b user in the screenshot had system Administrators role as shown in the image above?
    If no then account b user might be Missing the user(systemuser),roles table read permission.
     
    Or may be email mismatch because of external user or more
     
    In Power Apps, User().Email returns the User Principal Name (UPN) of the logged-in user (the ID they use to log in).
    In the Dataverse Users (systemuser) table, this corresponds to the User Name field (logical name: domainname), not necessarily the "Primary Email" field.
    Here is the breakdown of the fields:
     
    Why LookUp might be failing
     
    currently looking up based on Primary Email:
     
    LookUp(Users, 'Primary Email' = User().Email)
     
    If Account B has a different login ID (UPN) than their email address (e.g., Login: admin@org.onmicrosoft.com, Email: info@org.com), this lookup will fail.
    The Fix
    Change your OnStart code to match against the User Name (Domain Name) instead, which is the actual system identifier.
     
    Set(
        gblCurrentUser, 
        LookUp(Users, 'User Name' = User().Email) // logical name: domainname
    );
     
    Note: In some Dataverse environments, the display name for domainname is "User Name" or "Domain Name".

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard