Hiding and Showing Controls on App with Role-Based Permissions

Introduction

We all know that we can break and handle permission on Sharepoint lists and list items. We can also restrict user access to Power Apps and forms. We can enable and disable controls depending on statuses and roles in PowerApps.

Scenario

In this article, we shall see how to make PowerApps role-based controls.

Objective

Design your form as per your needs. I have my buttons in different places for different purposes.

I will show you two scenarios with two different examples.

Step 1. Example

I would like to show the button only when the status is in the approved phase, so,

The below screen shows, and for learning purposes, that status is in the approved phase.

Status

Now I shall write the formula either on the visible property or Displaymode property and the formula is given below.

Step 2. Visible Property

Visible property returns true or false.

Visible Property

Suppose we want to check the condition for more than one value then we either use the || (OR) or && (And) operator. For example, given below.

Check the condition

Step 3. DisplayMode Property

DisplayMode returns the modetype, we can set colors for disabled mode or focused mode too.

DisplayMode Property

Step 4. Role-based visibility

If the logged user is not part of the HRHead column, which is a people picker of form, then the button should not show even if it's in correct status. Below we can see the button is hidden. The same applies to display mode and also for roles based on a form level.

HRHead column

Note. Using in property we can check in single select people picker as well as multi select people picker.User().Email returns the logged user.

Step 5. App OnStart

Note. Instead of using User().Email in the formula, we can use this function on App OnStart and save the value in a variable and use that variable wherever required, this increases the performance of the app.

App OnStart

However, to view the result, we must click on Run OnStart on the app.

Run OnStart

Step 6. Formula changes are shown below using the variable

Variable

Conclusion

In the above article, we saw how to make controls visible on role-based from form. Either on logged-in users or people entered in the people picker or depending upon the statuses. This is a frequently needed scenario.


Similar Articles