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:
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.
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
- In SharePoint Online, create a custom list called Leave Request
- Setup the following columns in the custom list
- Leave Type (Choice)
- Number of days (Number)
- Description (Multiple lines of text)
- Create a new PowerApp to automatically generate a default app
- Click on the editable form page
- Click on the description control, and select advanced options on the right hand panel
- Unlock the advanced properties
- 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. - 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. - 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 - 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