When creating a PowerApp (an app created with PowerApps), you sometimes want to only show a button based on the role of the user, aka you want role-based access.
Another often required feature is easy role management for the PowerApp owner. Working with a SharePoint list with custom permissions on it will do just fine for that.
But can both be combined? Yes, it can!
Create a SharePoint list (called “Roles App”) and add a “People or Group” field to it called “Employee”. Now add items to the list. For example:
Title | Employee |
---|---|
Role One | user1 |
Role Two | user1 |
Role Three | user2 |
In the PowerApp, put the following in the property OnStart
of the start screen.
ClearCollect(rolesApp, 'Roles App');
Set(currentUser, User());
ClearCollect(roles, Filter(rolesApp, Employee.Email=currentUser.Email));
Set(varRoleOne, LookUp(roles, Title="Role One", Title));
In the PowerApp, put the following in the property Visible
of the button:
If(IsBlank(varRoleOne), false, true)
The button is now shown only for users which have the role “Role One” defined in the SharePoint list.