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

Access Web App | Filter a view by current user login (deprecated)

Update (April 1 2017): Microsoft has released an update that willl stop the creation of new apps starting June 2017, and shut down any remaining apps by April 2018. See more here

The problem One of the things I needed to do lately was see if a view within Access Web Apps can be configured to filter data that is related to the logged in user. e.g. as a user I want to be able to view a list of projects where I had been assigned as the project owner.

In SharePoint, this would have been quite easy to achieve as we can create a view and set the filter to {column name} is equal to [me].

Unfortunately Access Web Apps does not quite work this way:

No people picker control in Access Web Apps - this means we need to store and manage our own list of user data within a table in your Access Web App Database (or find a way to link a table with SharePoint's user profile or hidden user information list).Access Web Apps is a relational database - this means the approach to filtering a table view is…

Nintex Workflow | parsing JSON responses from json-only web requests

Update 03/08/16:
Logic Apps has gone GA, and has undergone a major v2 change since this post was written. For the most part, the core actions remain the same but just renamed or work a little differently e.g. http listener (now known as "When an http request is received" + "Received") and conditions (now triggered via the add a condition" button instead of being configured inside the http action.)

It is worth noting that the BizTalk JSON Encoder API app can no longer be found in the marketplace. This is now a native function in Logic Apps. Though, I'll try to refresh this post with the how to do it in the version of Logic Apps that GA'd, I'm not sure when I will have to do it, so if you can't wait, I suggest looking at the xml function can be found here.

Update 07/08/16:
Steps for new Logic App UI that has GA have been added into the solution section below.
The problem
One of the things I have been working on lately in the Nintex Workflow world,…

An intro to conditional validation and formatting in PowerApps (using SharePoint as a data source)

The Problem What if we need to create a form that changes it's behaviour based on the answer entered by the user.

For example, we need to build a leave request form that: Shows the comment field if applying for a sick leave, but hides the comment field if applying for a annual leaveRequires the requestor to write a comment if their sick leave is more than 1 day, but is optional if sick for just 1 day.  The default form interface for custom lists in SharePoint Online can be used for basic scenarios, but doesn't provide an easy way to add business logic described above (unless you want to write some javascript)

In the past InfoPath would have been the tool of choice for many, however this tool is now in maintenance mode and whilst it will still be supported for a wee while there will be no improvements or enhancements to the platform.

The Solution This is where PowerApps come in. PowerApps is now the platform that is recommended by Microsoft as a way for business users to create…