Skip to main content

Only show a control to an employee's manager in PowerApps (using SharePoint as a data source)

The Problem

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.

The Solution

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

The steps in this blog are also shown in the video below

The steps below shows a sample scenario of a expense request form
  1. In SharePoint Online, create a custom list called Expense Request
  2. Setup the following columns in the custom list
    1. Approval (Choice)
    2. Value (Number)
    3. Employee (Person)
  3. Create a new PowerApp connected to your Expense Request list
  4. From the ribbon, click on Content > Data Sources
  5. Add a new connection to Office 365 Users
  6. Click on the editable form page
  7. Click on the Employee control, and select advanced options on the right hand panel
  8. 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
  9. 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
  10. Click on the Approval control, and select advanced options on the right hand panel
  11. Unlock the advanced properties
  12. 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.
  13. 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

Next Steps

  • Have you created something similar using PowerApps? Please share your experience below.

Popular posts from this blog

SharePoint | Set default value of date field to last day of the month

One of the things, that I needed to do recently is find a way to set the default value of a date field to the last day of the month. Though some content were really helpful in getting me on the way to solving the problem, I thought I'd post the formula required to make it easier for others looking to do the same in the future. What I wanted to do  The steps below describe what I wanted to achieve: User uploads a file into a document library A date column will automatically be populated with the date representing the end of the month (calculated based on the date the file was uploaded) How do we do this? Open your column settings for your date field Under the Additional Column Settings, set the default value option to Calculated Value Enter the the formula below: =(DATE(YEAR(TODAY()),MONTH(TODAY())+1,DAY("1-Apr-2008"))) - (1) Click save and that's all you need to do What does the formula above do? The formula above is quite simple.

Uploading a file from a SharePoint document library into an Azure Blob Storage with Microsoft Flow (or Logic App)

The Problem One of the things that I've been experimenting with lately is Microsoft Flow . The service allows you to build process automation to facilitate transfer of information from one system to another easily. One scenario I wanted to try out is to be able to copy/move a file from SharePoint to an Azure Blob Storage. There are a number of reasons that you may want to do this: Archive files that are no longer needed Upload a copy of a file (usually an image) into a Blob Storage so that images can be hosted in a CDN to optimize page load performance In the past doing something like this would have required some form of custom development e.g. a remote event receiver. However the introduction of Microsoft Flow and Logic Apps has created another alternative that is worth exploring.... Update 30/09/16:  If you are looking to put your assets into a CDN to make it load faster, then it's worth checking out the new Preview Release  Office 365 Public Content Delivery