Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Fetch XML linked entity

(0) ShareShare
ReportReport
Posted on by 1,760

Hey guys

I've got a fetch query that I can't seem to get correct. I want to use this query outside of advanced find but I cant seem to get my desired results.

I want to get appointments where the regarding is either a contact with a business category of

100000034

100000018

or accounts where the business category is

100000034

100000018

so lets say I have 3 appointments where the regarding is a contact and 5 appointments where the regarding is an account: how do I get all 8 and only the 8. Using the fetchxml tester from the XrmToolBox I'm getting more than 20 which is wrong? Any help would be appreciated guys. Here's my fetch:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

<entity name="appointment">

<attribute name="subject" />

<attribute name="statecode" />

<attribute name="scheduledstart" />

<attribute name="scheduledend" />

<attribute name="createdby" />

<attribute name="regardingobjectid" />

<attribute name="instancetypecode" />

<attribute name="activityid" />

<order attribute="subject" descending="false" />

<filter type="and">

<condition attribute="scheduledstart" operator="on-or-after" value="2019-04-30" />

<condition attribute="scheduledstart" operator="on-or-before" value="2020-05-30" />

</filter>

<link-entity name="account" from="accountid" to="regardingobjectid" link-type="outer" alias="ad">

<filter>

<condition attribute="exe_businesscategory" operator="in">

<value>100000034</value>

<value>100000018</value>

</condition>

</filter>

</link-entity>

<link-entity name="contact" from="contactid" to="regardingobjectid" link-type="outer" alias="ab">

<filter type="and">

<condition attribute="exe_businesscategory" operator="in">

<value>100000034</value>

<value>100000018</value>

</condition>

</filter>

</link-entity>

</entity>

</fetch>

  • T.I.A Profile Picture
    T.I.A 1,760 on at
    RE: Fetch XML linked entity

    Thanks Andrew, you nailed it!

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Fetch XML linked entity

    I understand. I posted wrong version initially. Can you confirm that you tested one that is posted now?

  • T.I.A Profile Picture
    T.I.A 1,760 on at
    RE: Fetch XML linked entity

    When I'm using the Fetchxml tester I get an error because the business category doesn't live on the appointment entity, it lives on the other entities (contact, account)

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Fetch XML linked entity

    Hello,

    Try to use following FetchXml:

      
        
        
        
        
        
        
        
        
        
          
          
          
            
              
              
                100000034
                100000018
              
            
            
              
              
                100000034
                100000018
              
            
          
        
        
        
        
      
    

  • T.I.A Profile Picture
    T.I.A 1,760 on at
    RE: Fetch XML linked entity

    I don't intend to use it in Dynamics directly, I'm using it in power bi to query the data

  • Mayank Pujara Profile Picture
    Mayank Pujara 830 on at
    RE: Fetch XML linked entity

    I believe you will need to separate these two queries , one for contact and another one for account..

    as far I know CRM system does not allow to set OR on two linked entities, you can set OR with in entity's attribute only...

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans