Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

FetchXML from link entity twice

Posted on by Microsoft Employee

I am trying to pull data from same linked entity twice like below:

<link-entity name='jt_country' alias='countrybill' to='billto_country' from='jt_name' link-type='outer'>
<attribute name='jt_countrycode' alias='billcountry'/>
</link-entity>
<link-entity name='jt_country' alias='countryship' to='shipto_country' from='jt_name' link-type='outer'>
<attribute name='jt_countrycode' alias='shipcountry'/>
</link-entity>

I am attempting to do this to pull this entity twice joining on 2 different fields to get the country for billing and country for shipping. I can get it to pull the first alias, but not the second. What am I missing?

 

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: FetchXML from link entity twice

    It seems to be the same kind of FetchXml I posted above (two links, two aliases) - you can see how different codes show up for the bill to and ship to.

    Are you certain there is, actually, a billto/shipto country for those country names? If there is no match, you won't have those attributes in the resultset.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: FetchXML from link entity twice

    Tried what you are showing. Maybe, I am not adequately explaining. I need both the shipcountry and billcountry on the same line.  The link works partially. Since I need to do it for both the billto as well as the shipto, I am doing the link twice with differing alias and joining on the billto_country on one and shipto_country on the other. The problem I am facing is that is pulling it from the first link-entity alias, but not the second. 

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: FetchXML from link entity twice

    Ok. I will try that out

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: FetchXML from link entity twice

    I'm still wondering where are you trying to run that fetch and if there are countries with the right names..

    You can run fetchXml using webAPI.

    Here is what I got (different prefix for the country entity, but, in general, just the same query I believe):

    https://<ORG ROOT>/api/data/v8.2/salesorders?fetchXml=<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

     <entity name="salesorder">

       <attribute name="name" />

       <attribute name="customerid" />

       <attribute name="statuscode" />

       <attribute name="totalamount" />

       <attribute name="salesorderid" />

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

    <link-entity name='new_country' alias='countrybill' to='billto_country' from='new_name' link-type='outer'>

    <attribute name='new_code' alias='billcountry'/>

    </link-entity>

    <link-entity name='new_country' alias='countryship' to='shipto_country' from='new_name' link-type='outer'>

    <attribute name='new_code' alias='shipcountry'/>

    </link-entity>

     </entity>

    </fetch>

    countries.PNG

    This, actually, shows two things:

    - The query should work (highlighted line)

    - If there is no match, you won't see those attributes in the result (the other line)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: FetchXML from link entity twice

    Not giving me an error, but only pulling data from the first entity. The 2nd entity alias, it does pull from. Not sure what I am doing wrong.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: FetchXML from link entity twice

    Is it giving you an error? Where are you doing it(plugin/ssrs..)?

    Is there a country record with the right name?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans