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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

FetchXML from link entity twice

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • ashlega Profile Picture
    34,477 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?

  • Community Member Profile Picture
    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.

  • Suggested answer
    ashlega Profile Picture
    34,477 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
    on at
    RE: FetchXML from link entity twice

    Ok. I will try that out

  • Community Member Profile Picture
    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. 

  • ashlega Profile Picture
    34,477 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.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans