Role-based access control in a PowerApp based on items in a SharePoint list - #ARCHIVED#

This content has been archived. It may no longer be relevant.  

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:

TitleEmployee
Role Oneuser1
Role Twouser1
Role Threeuser2
SharePoint list items

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.