cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Chandu
Helper III
Helper III

Filter Contacts Entity based on Selected Account from Dynamics CRM

In Screen1 I am having Gallery1, in which I am Showing list of Account Names from Account Entity through Dynamics CRM.

In Screen2, I am having Gallery2, in which I am showing list of Contact Names from Contact Entity with respect to the selected Account from Gallery1.

In Account Entity (AccountID[GUID], Account Name, Primary Contact[GUID], Company Name as lookup field of Contact[GUID])

In Contact Entity (ContactID[GUID], Contact Name, Company name as Account Name[GUID])

Now in Gallery2, I am getting only Company name as Account Name list from contact Entity as I wrote Gallery2 Items: Filter(Contacts, companyName in Gallery1.Selected.Account)

To get Primary Contact also I wrote Gallery2 Items: Filter(Contacts, companyName in Gallery1.Selected.Account and ContactID in Gallery1.Selected.PrimaryContact). But, I am not getting contacts list, it is showing empty even though Contacts are there for selected account.

Can anyone help me how to get all contacts when respective account is selected.

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Chandu ,

Based on the Filter formula you provided, I think there is something wrong with it. Actually, the "Company Name" field in Contacts Entity is a Customer LookUp field (Polymorphic lookups), which can refer to a record from either the Accounts entity or the Contacts entity.

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/working-with-references#show-the-fields...

 

On your side, please consider modify your Filter formula as below:

Filter(Contacts, AsType('Company Name', [@Accounts]).Account = Gallery1.Selected.Account)

or

Filter(Contacts, AsType('Company Name', [@Accounts]).'Account Name' = Gallery1.Selected.'Account Name')

 

In addition, the D365 CRM Entity is actually based on CDS Entity, so please consider remove the D365 CRM Entity connections from your app, instead, create a connection to the Contacts Entity and Accounts Entity in your CDS, then try above Filter formula again, check if the issue is solved.

 

If you just want to use D365 CRM Entity in your app, please consider modify your second Filter formula as below:

Filter(
       Contacts, 
       'Company Name' = Gallery1.Selected.Account,
       Contact = Gallery1.Selected.'Primary Contact'.Contact // Modify formula here
)

or

Filter(
       Contacts, 
       parentcustomerid = Gallery1.Selected.accountid,
       contactid = Gallery1.Selected.primarycontactid.contactid // Modify formula here
)

Note: The 'Primary Contact' field is actually a LookUp field in your Accounts Entity. The screenshot as below:

2.JPG

Note: Please add CDS Entity connection in your app instead of D365 CRM Entity connections.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-xida-msft
Community Support
Community Support

Hi @Chandu ,

Based on the Filter formula you provided, I think there is something wrong with it. Actually, the "Company Name" field in Contacts Entity is a Customer LookUp field (Polymorphic lookups), which can refer to a record from either the Accounts entity or the Contacts entity.

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/working-with-references#show-the-fields...

 

On your side, please consider modify your Filter formula as below:

Filter(Contacts, AsType('Company Name', [@Accounts]).Account = Gallery1.Selected.Account)

or

Filter(Contacts, AsType('Company Name', [@Accounts]).'Account Name' = Gallery1.Selected.'Account Name')

 

In addition, the D365 CRM Entity is actually based on CDS Entity, so please consider remove the D365 CRM Entity connections from your app, instead, create a connection to the Contacts Entity and Accounts Entity in your CDS, then try above Filter formula again, check if the issue is solved.

 

If you just want to use D365 CRM Entity in your app, please consider modify your second Filter formula as below:

Filter(
       Contacts, 
       'Company Name' = Gallery1.Selected.Account,
       Contact = Gallery1.Selected.'Primary Contact'.Contact // Modify formula here
)

or

Filter(
       Contacts, 
       parentcustomerid = Gallery1.Selected.accountid,
       contactid = Gallery1.Selected.primarycontactid.contactid // Modify formula here
)

Note: The 'Primary Contact' field is actually a LookUp field in your Accounts Entity. The screenshot as below:

2.JPG

Note: Please add CDS Entity connection in your app instead of D365 CRM Entity connections.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,491)