Skip to main content

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 leave
  • Requires 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 business forms/applications on top of SharePoint (or other data sources).

PowerApps provides us with the ability to define business rules against controls in the form by using formulas not too dissimilar to excel formulas.

The Steps

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

The steps below shows a sample scenario of a leave request form
  1. In SharePoint Online, create a custom list called Leave Request
  2. Setup the following columns in the custom list
    1. Leave Type (Choice)
    2. Number of days (Number)
    3. Description (Multiple lines of text)
  3. Create a new PowerApp to automatically generate a default app
  4. Click on the editable form page
  5. Click on the description control, and select advanced options on the right hand panel
  6. Unlock the advanced properties
  7. Click on the Leave Type control and note the value in the Update property.

    We will use this value in our formula to look at the value of the leave type selected by the user.
  8. Click on the Description control again and set the formula in the visible property to If(DataCardValue6.Selected.Value = "Sick Leave",true)
    This will  display the Description control if the Leave Type is equal to Sick Leave.

  9. Click on the Number of days control and note the value in the Update property.

    We will use this value in our formula to look at the number of days entered by the user
  10. Click on the Description control again and set the formula of the required property to If(Value(DataCardValue7.Text) > 1,true)

    This will make the the Description control mandatory if  the number of days entered is more than 1.

Testing the app

Click the play button on the top right to test out your app. You should see the following results
  • Select Annual Leave and see the description control disappear
  • Select Sick Leave and see the description control appear
  • Enter 1 into the Number of days and see that the description control is optional
  • Enter 2 into the Number of days and see that the description control is mandatory

Next Steps

  • Have you created business forms using PowerApps? Please share your experience below.
  • Check out the formula reference from the PowerApps site for more information on writing formulas

Popular posts from this blog

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 neededUpload 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 Network (CDN) capab…

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 onThe manager of the user specified in the employee controlNote: Whilst this solution makes it difficult for …