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!