Owner, Customer, and Regarding for canvas apps

Common Data Service polymorphic lookups are now available from canvas apps.  You can now:

  • Access, set, and filter on the Owner field of any record.
  • Access and set the Company Name field (a Customer data type) of the Contacts entity.
  • Access and set the Regarding field of activity entities such as Faxes, Phone Calls, Email Messages, etc.
  • Access the list of all Activities for a record.
  • Access the list of Notes for a record.

For example, this very simple app filters the Accounts entity based on Owner, displays the type of Owner and Owner’s name in the second line of the gallery, and can set the Owner for the selected account to either a User or a Team:

The following app is showing all the activities for an account, be they from the Faxes, Phone Calls, Chats, or Email Messages entities, with activity specific details shown for each:

Read the article Understand record references and polymorphic lookups for step by step instructions for creating these examples and more details.

Record References

We have added a new data type to the language: record reference.  Similar to references in other languages, a record reference is a pointer to a specific record in a specific entity.  A record reference carries with it the entity information allowing it to point to records in any entity, which differs from a normal lookup that can only point to records in one entity.

Record references can be used just like a full record in Filter and Patch calls:

Filter( Accounts, Owner = First( Teams ) )
Patch( Accounts, First( Accounts ), { Owner: First( Users ) }

But when it comes time to read fields from the record reference, something more is needed.  Since it can point to any entity, we won’t know which entity until the app is running.  Our strongly typed formulas are going to need to be more dynamic.

We’ve added two new functions to help with this:

  • IsType – Checks if a record reference is of a particular entity type.
  • AsType – Casts a record reference to a particular entity type.

With these, we can write this formula that displays the name of the Owner taken from two differently named fields, based on the entity type of the Owner:

If( IsType( ThisItem.Owner, Users ), 
    AsType( ThisItem.Owner, Users ).'Full Name', 
    AsType( ThisItem.Owner, Teams ).'Team Name' )

Using these functions makes for a long formula but it is easy to understand what it is doing.   We have some ideas for additional helper functions that would simplify this further but we’d like to hear your feedback first.

A few notes

This feature is still rolling out.  While the IsType and AsType functions are available in all regions, you also need an updated connector.  If you’d like to work with it right now, provision a trial environment in the Asia region where the connector has already landed.  The connector will finish deploying early next week.

This feature is under the Preview feature for relational data, option sets, and other CDS enhancements.  It is not yet complete with caveats noted in the documentation.   For example, there is no way yet to change a polymorphic lookup value from within a form control.   We are actively working to close these gaps.

As always we very much value your feedback.  Please leave comments here and in the PowerApps community.