Role Based Security Trimming In Power Apps Canvas App

In this article we will learn how we can implement role base security trimming in the Power Apps Canvas app. This is useful if we don’t want to show a few links of the left navigation to all users, and make it so only administrators can see those links and the screens associated with those links.

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

Below are the steps to follow.

App. OnStart – On application start.

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

Here usethe  following code:

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

Set(UserEmail,User().Email);

SharePoint list

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

Admin Link

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

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

This code first checks whether the logged in user email is present in the 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 counts the number of rows returned by the filtered Admin list. If the count is more than 0, this means the user is part of the Admin list and an Admin link will be visible to user.