Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Custom Contact Subgrid FetchXML Query Timing Out - Using Connection Roles

(0) ShareShare
ReportReport
Posted on by

We have a pretty complex lookup filter that we use to display "Associated Contacts" so the user doesn't have to enter a duplicate when one billing account has multiple service accounts.  The problem is, during initial development, we had a requirement to associate the "Customer" that was attached to a lead, opportunity, quote, case, etc... to the "Service Account", or as we call it, "Site".  This is because the Lead starts out at the Site address for us, then we associate it to a related Customer if that customer already is in our system.

We use connection roles for this when there are multiple "Sites" for a "Customer".  Think McDonalds Corporate for the Billing Account.. and various locations as the Sites.

So, when adding a related contact to an Opp or a Quote, the basic view will only relate the Contact to the "Site's" Contacts.  We added a custom view via JavaScript that looked up all "Associated Contacts".

The problem is this fetchxml times out almost all the time before data can be displayed in the lookup grid.  

Is there a better way to do this now?  When using connection roles to display all related contacts to either the "Site" or the "Customer"?

var lookupFilter =
'<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >' +
'<entity name="contact" >' +
'<attribute name="contactid" />' +
'<attribute name="fullname" />' +
'<attribute name="emailaddress1" />' +
'<attribute name="telephone1" />' +
'<attribute name="parentcustomerid" />' +
'<link-entity name="account" from="accountid" to="parentcustomerid" link-type="outer" alias="ca" >' +
'<attribute name="accountnumber" />' +
'</link-entity>' +
'<link-entity name="new_contact_account" from="contactid" to="contactid" link-type="inner" alias="nton" >' +
'<link-entity name="connection" from="record2id" to="accountid" link-type="outer" alias="con" >' +
'<filter type="or" >' +
'<condition attribute="record2roleid" operator="in" >' +
'<value uiname="Site" uitype="connectionrole">CA731AB5-D143-E811-A834-000D3A37C8E1</value>' +
'<value uiname="Customer" uitype="connectionrole">E45A17A9-D143-E811-A834-000D3A37C8E1</value>' +
'</condition>' +
'<condition attribute="record1roleid" operator="in" >' +
'<value uiname="Site" uitype="connectionrole">CA731AB5-D143-E811-A834-000D3A37C8E1</value>' +
'<value uiname="Customer" uitype="connectionrole">E45A17A9-D143-E811-A834-000D3A37C8E1</value>' +
'</condition>' +
'</filter>' +
'</link-entity>' +
'<link-entity name="connection" from="record1id" to="accountid" link-type="outer" alias="con2" >' +
'<filter type="or" >' +
'<condition attribute="record2roleid" operator="in" >' +
'<value uiname="Site" uitype="connectionrole" >CA731AB5-D143-E811-A834-000D3A37C8E1</value>' +
'<value uiname="Customer" uitype="connectionrole" >E45A17A9-D143-E811-A834-000D3A37C8E1</value>' +
'</condition>' +
'<condition attribute="record1roleid" operator="in" >' +
'<value uiname="Site" uitype="connectionrole" >CA731AB5-D143-E811-A834-000D3A37C8E1</value>' +
'<value uiname="Customer" uitype="connectionrole" >E45A17A9-D143-E811-A834-000D3A37C8E1</value>' +
'</condition>' +
'</filter>' +
'</link-entity>' +
'</link-entity>' +
'<filter type="and" >' +
'<condition attribute="statecode" operator="eq" value="0" />' +
'<filter type="or" >' +
'<condition entityname="con" attribute="record1id" operator="eq" value="' + accountId + '" />' +
'<condition entityname="con" attribute="record2id" operator="eq" value="' + accountId + '" />' +
'<condition entityname="con2" attribute="record1id" operator="eq" value="' + accountId + '" />' +
'<condition entityname="con2" attribute="record2id" operator="eq" value="' + accountId + '" />' +
'<condition entityname="nton" attribute="accountid" operator="eq" value="' + accountId + '" />' +
'</filter>' +
'</filter>' +
'</entity>' +
'</fetch>';

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans