Customising SharePoint list forms with PowerApps – part two

This series of articles will show you how to customise a SharePoint list form using PowerApps:

  • part one – customise a list form, create new, edit, and view forms, and wire up the buttons (read now)
  • part two – create cascading drop-downs (read below)
  • part three – create tabs so long forms can be broken into sections (coming soon)
  • part four – use collections and patching to create a parent/child relationship between two lists (coming soon).

Part 2 – Cascading drop-downs

From the research I have done and the tutorials by Shane Young and others I have worked through, the consensus at this point is that SharePoint lookup columns “do not play well” when customising a form in PowerApps.

I have tried various combinations to use filter, sort and distinct functions on lookup columns without success. The approach seems to be if you have a second list that would normally be your source for the lookup column to uses a text column and let PowerApps do all the magic of pulling the list into a drop-down control, then write the chosen selection into the list’s text field.

This is very similar to how you would have done it in the old days with InfoPath. In InfoPath you would create a Data Connection to your lookup list and connect it to the drop-down.

In this example I have a second list called ‘Australian City’ which gives me State and City. City is unique but State is not.

Screenshot of Sharepoint library with State and City column titles

The list I am customising in PowerApps has two ‘Single line of text’ fields for State and City. To reiterate these are text columns and not lookup columns.

If you try to add a drop-down control to a screen, it will be added ‘outside’ the form. So instead select your Ffrm in the left-navigation and then add the two fields from your list.

Screenshot of PowerApps menu - 'FormEdit'

Now that they are on the form as a datacard, unlock the datacard and then delete the text control.

Screenshot of PowerApps - 'Edit item'

Add a drop-down control in its place. You may need to re-align the error message and resize the card to suit. Change the control’s name to something more sensible, in my case I choose CityDropdown1.

The last red ‘x’ will be highlighting the ‘Update’ function on the datacard, as this will be trying to update the original control’s name. Change to ‘Update = CityDropdown1.Selected.Value’

Screenshot of PowerApps with Form edit drop down options

The next part is to wire up the drop-down control to pull the actual list of cities from the second list.

Select the drop-down control and from the properties pane choose your data source. If you have not made a connection to your lookup list then choose the ‘Add a data source’ button.

When you play in Preview, you will see the unfiltered list of cities in your drop-down control.

Screenshot of PowerApps with Edit item options

Repeat the same steps for your state control.

These controls are now pulling in the data and we just need to filter the list of states to remove duplicates and then cascade the drop-downs, so that when choosing the state of NSW, it filters the cities to be only the cities in NSW.

Drag the state control above the city control as the end user will choose the state first.

To filter the state drop-down control:

Items = Sort(Distinct(‘Australian City’.State, State), Result, Ascending)

Screenshot of PowerApps with Edit items menu

As I mentioned in the last article, PowerApps cache and sometimes when you make a change and then try it in Preview mode, you may find your last change is not applied. If this happens to you, when you paste in the above line, simply copy that last line into your clipboard, delete the ‘Items’ line, preview, then re-paste back into Items and preview again. There seem to be a few quirks that we have to live with at this point in time.

To filter our cities control, in ‘Items’ add the following :

Filter(‘Australian City’,State=StateDropdown1.Selected.Value)

Screenshot of PowerApps with Edit items menu

Publish to your list, refresh twice and you have a cascading drop-down.

Screenshot of SharePoint library with Edit item information and drop downs

Do you have any SharePoint or Microsoft PowerApps questions? We’re a team of Office 365 experts ready to answer!