<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=612681139262614&amp;ev=PageView&amp;noscript=1">
Skip to content

Need help? Talk to an expert: phone(904) 638-5743

Polymorphic Data Types in Canvas Apps

Polymorphic Data Types in Canvas Apps

In this Pragmatic Works training video, Nate Halliwell, Senior Trainer, explores the concept of polymorphic data types in Power Apps Canvas Apps. While the term may sound complex, Nate reassures viewers that polymorphic data types are simple to use once their purpose is understood. They extend the functionality of lookup columns by allowing a single field to reference objects from multiple tables, bringing flexibility to app design.

 

Lookup Columns vs. Polymorphic Data Types

  • Lookup column: Stores a reference to an object from one specific table. For example, a contact record may reference an account record.
  • Polymorphic data type: Stores a reference that could come from multiple tables. A common out-of-the-box example is the Customer data type in Dataverse, which can point to either an Account or a Contact.

Practical Example — Ledger Application

Nate demonstrates polymorphic data types using a simple ledger app. The app tracks money owed or receivable, along with who the transaction involves — which could be a person (contact) or a company (account). This scenario highlights why polymorphic data types are powerful: they let a single column handle both possibilities.

Building the App Step by Step

  1. Create the gallery and form: Nate sets up a gallery to display ledger items and a form to add new ones. Fields include amount, ledger type (payable/receivable), and customer.
  2. Add the customer field: When inserting the polymorphic field into the form, the data card appears empty. Unlike standard lookups, it requires manual configuration.
  3. Connect necessary data sources: Because the customer field may reference both Accounts and Contacts, both tables must be added to the app as data sources.

Configuring the Data Card

  • Add display name: Insert a label to show the field name (e.g., “Due To/From”).
  • Insert combo boxes: Add two combo boxes: one for Accounts and one for Contacts. Populate them from their respective tables.
  • Provide user control: Insert a toggle to switch visibility between the two combo boxes. The toggle is labeled “Accounts” (off) and “Contacts” (on).
  • Control visibility: Use formulas to show only the relevant combo box depending on toggle position.

Updating the Data

Standard fields automatically configure an Update property. Polymorphic data cards do not. Nate sets the update property manually with a conditional formula:

  • If the toggle = Contacts → Submit the selected contact.
  • If the toggle = Accounts → Submit the selected account.

This ensures the form writes the correct record type back to Dataverse.

Testing Submissions

Nate tests by adding new records:

  • Owing Brian Knight $50 (Contact).
  • Receiving $100 from ABC Corp (Account).
  • Owing $200 to Dunder Mifflin (Account).
  • Receiving $300 from Marshall Butler (Contact).

All transactions appear correctly in the gallery, confirming the submission logic works.

Displaying Data in the Gallery

Displaying polymorphic data requires more than just referencing the field. Since the type can vary, Power Apps does not automatically recognize whether the record is an Account or a Contact. Nate uses the AsType function combined with IfError to handle both cases:

  1. Attempt to treat the field as an Account and display the Account Name.
  2. If that fails, fall back to treating it as a Contact and display the Full Name.

This logic ensures that the gallery shows the correct name, whether the customer is a person or a company.

Key Takeaways

  • Polymorphic data types allow a single column to reference multiple tables, offering flexibility in app design.
  • They require manual setup in forms: adding data sources, combo boxes, and visibility controls.
  • Update properties must be configured with conditional formulas to submit the correct record type.
  • Displaying polymorphic fields requires functions like AsType and IfError to handle different record types seamlessly.

Conclusion

Nate Halliwell’s demonstration shows that polymorphic data types in Canvas Apps are not intimidating once broken down step by step. They provide powerful flexibility for scenarios where a single field needs to reference more than one table, such as handling both individuals and organizations in the same system. With proper configuration, polymorphic data types become an essential tool in any Power Apps developer’s toolkit.

Don't forget to check out the Pragmatic Works' on-demand learning platform for more insightful content and training sessions on Canvas Apps and other Microsoft applications. Be sure to subscribe to the Pragmatic Works YouTube channel to stay up-to-date on the latest tips and tricks. 

Sign-up now and get instant access

Leave a comment

Free Community Plan

On-demand learning

Most Recent

private training

Hackathons, enterprise training, virtual monitoring