In my previous blog post, I wrote a basic tutorial on configuring PowerApps to conditionally show/hide and make mandatory/optional a control based on the answer provided in a previous control.
In this blog post we will expand on that scenario to create a form that only shows a control called approval status to a user if that logged in user is the manager of the user specified in the employee control.
This means when the manager is using the application, they can change the status to approved. Meanwhile, a user that is not a manager of the person specified in the employee cannot change the status to approved.
Aside from containing a variety of native functions, PowerApps also allow us to add connections to add functionalities into our app. In this case we will add the Office 365 Users connection so that we can get information on:
- The user that is logged on
- The manager of the user specified in the employee control
Note: Whilst this solution makes it difficult for non-managers to change the approval status, it does not prevent users from changing the status at the data level in SharePoint e.g. editing the out of the box SharePoint form or editing the list via datasheet view.
The steps in this blog are also shown in the video below
The steps below shows a sample scenario of a expense request form
- In SharePoint Online, create a custom list called Expense Request
- Setup the following columns in the custom list
- Approval (Choice)
- Value (Number)
- Employee (Person)
- Create a new PowerApp connected to your Expense Request list
- From the ribbon, click on Content > Data Sources
- Add a new connection to Office 365 Users
- Click on the editable form page
- Click on the Employee control, and select advanced options on the right hand panel
- Note the configurations in the Display (e.g. Email is stored in Value1) and Update properties.
This will help you determine what information to pass to the Get Manager functionality of the Office 365 Users connection
- Check out the Office 365 Users documentation from Microsoft to get a feel for the formula you would need to get the email of a user's manager, as well as the email of the currently logged in user
- Click on the Approval control, and select advanced options on the right hand panel
- Unlock the advanced properties
- Find the Visible property and populate it with the following formula
If(Office365Users.Manager(DataCardValue6.Selected.Value1).Mail = Office365Users.MyProfile().Mail,true)
Note: "DataCardValue6.Selected" is the same value that you would have seen in the Update property of the Employee Control. "Value1" on the other hand is where email is stored in the Display property of the Employee Control.
- Save your app
Testing the app
Click the play button on the top right to test out your app. You should see the following results
- Log in as a manager of an Office 365 user
- Enter the user that you manage into the employee control
- You should see the approval status control appear
- Change the user in the employee control to someone you don't manage
- You should see the approval status control disappear
- Have you created something similar using PowerApps? Please share your experience below.