In this article, I demonstrate how to display the name of the parent Customer for a Contact on a Gallery or Form in a Canvas PowerApp.
The App used for this example is connected to the underlying Contacts and Accounts entities in Dynamics 365 using the Common Data Source (CDS) Connector.
In Microsoft Dynamics 365 the Company field on the Contact entity is a polymorphic lookup that allows the selection of either an Account or a Contact. The following image shows the Dynamics 365 lookup control for this field on the Contact form in a Dynamics 365 Model Driven App.
The Company field, for a Contact in Dynamics 365 is the Parent Customer field.
The following image shows a Canvas PowerApp screen with a Gallery on the left displaying a list of Contacts and a Detail Form on the right displaying the currently selected Contact. The fields displayed in the Gallery and on the Form include the Company; i.e. the name of the Parent Customer. For the currently selected Contact, Alex Wu, the parent Customer is the Account named “Northwind Traders”.
The formula for the Text property of the Company field in the Gallery and on the Form is displayed below. The logic is based on the fact that the Parent Customer is either blank, an Account, or a Contact. There are no other possible options for this lookup field.
The IsType and AsType functions are used to display either the parent Account Company Name or the parent Contact Full Name, depending on whether the Parent Customer is an Account, a Contact or is blank.
“ThisItem” refers to the current Contact record and ‘Company Name’ is the name of the Parent Company field for a Contact in the underlying CDS data source.
“[@Accounts]” and “[@Contacts]” are global disambiguation operators used to define the table type.
For this formula to work, the Canvas PowerApp needs to be connected to the Contacts and the Accounts entities.
This same approach applies to other Dynamics 365 polymorphic lookup columns such as Owner, which is a lookup to a User or a Team, in which case the Canvas App needs to be connected to the Users and Teams entities.
Refer to the following articles for additional detailed information: