Polymorphic Lookups in Microsoft Dataverse are powerful, but if not handled correctly, can cause problems in Canvas Apps filtering functions.
What is a Polymorphic Lookup?
Traditional lookup columns in Microsoft Dataverse link two tables together. For instance, you might have a Projects table and each Project belongs to a specific Account; so you would created a Lookup field on the Project table that links back to the Account table. Polymorphic Lookups differ in that they can be used to join one table with multiple other types of table. A common out-of-the-box Polymorphic column is the Regarding field, found on an Activity record – this allows an activity such as a Phone Call or Email to be set Regarding a variety of other tables, including Accounts, Contacts and Cases.
How can they cause a Canvas Power App to crash?
This scenario is specific to filtering and is currently a problem when playing the App in a web browser or via a mobile device. In the studio, where the App is built, the functionality works without issue. This suggests a possible bug that Microsoft may address in due course.
In this code example, imagine you filter the Activities table by a selected Case from a Gallery:
Filter( Activities, Regarding = CaseGallery.Selected )
As mentioned, this code performs as expected in the App Studio, but elsewhere, when the screen is visited, the App will crash and restart completely.
What is the fix?
The key is to use the IsType function to carry out an additional check on the table type as below:
Filter( Activities, IsType(Regarding,Cases) && Regarding = CaseGallery.Selected )
With this added check, the function behaves as expected across all platforms.
Summary
Although Microsoft Power Apps allow non-developers to construct complex Apps using a simple function set, there can still be scenarios that will catch out less experienced users. It’s important to refer to Microsoft’s Formula Reference where possible, or if you are an existing Strategy 365 client, getting in touch with one of our experts for further assistance.