web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Link multiple entities with FetchXML

(0) ShareShare
ReportReport
Posted on by

I have a requirement to fetch all the activities from custom entities and have it roll up into a parent custom entity. I tried to use the cascade all option on the relationships but I guess that dosnt work for custom entities for whatever reason. So Im stuck trying to code it. I have been trying to get the fetchXML working but I'm having difficulty linking two different entities and I'm not sure what is wrong. Im using the XRMToolBox FetchXML builder and when I run it it just tells me its invalid XML. I'm not sure what Im doing wrong. Any help is appreciated!

Salestrip being parent, Customer Visit being child and Account Affected being grandchild

XML below.

<fetch top="50" >
 <entity name="activitypointer" >
  <attribute name="createdon" />
  <attribute name="activityid" />
  <attribute name="prioritycode" />
  <attribute name="statecode" />
  <link-entity name="salestrip" from="salestripid" to="regardingobjectid" link-type="outer" >
  <link-entity name="customervisit" from="originatingtrip" to="salestripid" link-type="outer" >
   <filter type="and" >
    <condition attribute="customervisitid" operator="not-null" />
   </filter>
  </link-entity>
  <link-entity name="accountaffected" from="originatingtrip" to="salestripid" link-type="outer" >
   <filter type="and" >
    <condition attribute="originatingvisit" operator="not-null" />
   </filter>
  </link-entity>
  </link-entity>
  </entity>
  </fetch>

*This post is locked for comments

I have the same question (0)
  • Dynamics365 Rocker Profile Picture
    7,755 on at

    Have you checked in XRM tool XML checker?

    Try it after removing:

     <link-entity name="salestrip" from="salestripid" to="regardingobjectid" link-type="outer" >

  • Community Member Profile Picture
    on at

    I got it to where its working, and it returns the records for the first condition. I am having trouble getting it return records for both conditions. Ive tried adding a second filter and changing filter type between OR and AND.

    <fetch top="50" >

     <entity name="activitypointer" >

       <attribute name="createdon" />

       <attribute name="activityid" />

       <attribute name="prioritycode" />

       <attribute name="statecode" />

       <attribute name="regardingobjectid" />

       <attribute name="subject" />

       <filter type="or" >

         <condition entityname="accountaffected" attribute="originatingtrip" operator="not-null" />

         <condition entityname="customervisit" attribute="originatingtrip" operator="not-null" />

       </filter>

       <link-entity name="accountaffected" from="accountaffectedid" to="regardingobjectid" link-type="outer" />

       <link-entity name="customervisit" from="acntcustomervisitid" to="regardingobjectid" link-type="outer" />

     </entity>

    </fetch>

  • David Jennaway Profile Picture
    14,065 on at

    The structure of your FetchXml is correct. Are you sure each link-entity and condition is correct (you can test by selectively removing the conditions) ? And is what you posted the complete FetchXml - you refer to a 'second filter', but the above only has one filter expression, and also the custom fields don't have a prefix, so maybe you've made an error entering this into your post

  • Community Member Profile Picture
    on at

    I tried adding a second filter to see if it would work. I did get it working I had the wrong field for one of the linked entities.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans