Role Based Security Trimming In Power Apps Canvas App

In this blog, we will learn how to implement role base security trimming in Power Apps Canvas apps. This is useful in situations where we don’t want to show the few links of the left navigation to all users. Only Administrators will be able see those links and the screens associated with those links.

Below is the Admin link, which will be visible only to administrators. Other users who don’t have administrator rights will not see this link.

Here are the steps to follow:

App. OnStart – On application start.

This is when the application is loaded for the first time.

Here we will use the following code:

Create a global variable UserEmail to save, and use logged-in user email in whole application across all screens.

Set(UserEmail,User().Email);

SharePoint list

We will create a SharePoint list called "Admin," with a person type field named "Administrator," as shown below.

Admin Link

This is a button control in the left navigation of Power Apps apps. It should be visible only to administrators. We will set the visible property of this button as shown below.

btnAdmin.Visible = If(CountRows(Filter(Admin,UserEmail in Administrator.Email)) > 0,true,false)

This code first checks whether logged-in user email is present in SharePoint ‘Admin’ list or not. As you can see, the Filter function is filtering the Admin list by comparing the logged in user email with the Administrator.Email value. The CountRows function is counting the number of rows returned by the filtered Admin list. If count is more than 0, this means user is part of Admin list, and the Admin link will be visible to user.