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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Link an entity that isn't the “Primary” entity

(0) ShareShare
ReportReport
Posted on by

I've been asked to create a report on some data from CRM using FetchXML. I have never used this language before so I think this may be an easy question.

I have the following code:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="bie_backbonus" enableprefiltering="1">
    <attribute name="bie_backbonuscontractno" />
    <attribute name="bie_backbonusnoteforletter" />
    <attribute name="bie_offdate" />
    <attribute name="bie_ondate" />
    <attribute name="bie_backbonuscontractversion" />
    <attribute name="bie_backbonuscontractname" />
    <attribute name="bie_backbonuscontactname" />
    <attribute name="bie_legacybackbonuscode" />
    <attribute name="owneridname" />
    <attribute name="createdon" />
<link-entity name="bie_backbonusproductgroup" from="bie_backbonuscontractno" to="bie_backbonusid" alias="pg" link-type="outer">
    <attribute name="bie_tier2percent" />
    <attribute name="bie_tier2value" />
    <attribute name="bie_tier3percent" />
    <attribute name="bie_productsubtype" />
    <attribute name="bie_tier1value" />
    <attribute name="bie_tier3value" />
    <attribute name="bie_producttype" />
    <attribute name="bie_tier1percent" />
 </link-entity>
<link-entity name="bie_producttype" from="bie_name" to="bie_producttype" alias="p" link-type="outer">
    <attribute name="bie_producttypenl" />
</link-entity>
  </entity>
</fetch>

I have tried to link three entities above but the bie_producttype entity needs to link to the bie_backbonusproductgroup entity not bie_backbonus which I think it is. Is there a function or way to link to other entities than the "Primary" one?

I have also tried using http://www.sql2fetchxml.com/ but this produced code that my report couldn't read.

I am a SQL Developer and the code would be this if written in SQL:

SELECT  b.bie_backbonuscontractno
   ,b.bie_backbonusnoteforletter 
   ,b.bie_offdate
   ,b.bie_ondate
   ,b.bie_backbonuscontractversion
   ,b.bie_backbonuscontractname
   ,b.bie_backbonuscontactname
   ,b.bie_legacybackbonuscode
   ,b.owneridname
   ,b.createdon
   ,pg.bie_tier2percent
   ,pg.bie_tier2value
   ,pg.bie_tier3percent
   ,pg.bie_productsubtype
   ,pg.bie_tier1value
   ,pg.bie_tier3value
   ,pg.bie_producttype
   ,pg.bie_tier1percent
   ,p.bie_producttypenl
FROM bie_backbonus b
JOIN bie_backbonusproductgroup pg ON pg.bie_backbonuscontractno =    b.bie_backbonusid
JOIN bie_producttype p ON p.bie_name = pg.bie_producttype

Thanks in advance for any help

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi KrissWatts,

    It is possible to link multiple entities in one FetchXml query. Advanced Find or FetchXml Builder can assist you with creating the FetchXml query. I recommend reading this article on building queries with FetchXML and this article which talks about FetchXML generation methods.

  • KrissWatts Profile Picture
    on at

    Hi Adrian,

    I didn't know the FetchXML Builder existed, so thanks for this. I've completed the query now.

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Kriswatts,

    As suggested above, the best way to generate fetchxml is to use advance find or fetch tools.

    I have done some changes to you existing code, could you please try the below code and see if it works?

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="bie_backbonus" enableprefiltering="1">
        <attribute name="bie_backbonuscontractno" />
        <attribute name="bie_backbonusnoteforletter" />
        <attribute name="bie_offdate" />
        <attribute name="bie_ondate" />
        <attribute name="bie_backbonuscontractversion" />
        <attribute name="bie_backbonuscontractname" />
        <attribute name="bie_backbonuscontactname" />
        <attribute name="bie_legacybackbonuscode" />
        <attribute name="owneridname" />
        <attribute name="createdon" />
        <link-entity name="bie_backbonusproductgroup" from="bie_backbonuscontractno" to="bie_backbonusid" alias="pg" link-type="inner">
          <attribute name="bie_tier2percent" />
          <attribute name="bie_tier2value" />
          <attribute name="bie_tier3percent" />
          <attribute name="bie_productsubtype" />
          <attribute name="bie_tier1value" />
          <attribute name="bie_tier3value" />
          <attribute name="bie_producttype" />
          <attribute name="bie_tier1percent" />
          <link-entity name="bie_producttype" from="bie_name" to="bie_producttype" alias="p" link-type="inner">
            <attribute name="bie_producttypenl" />
          </link-entity>
        </link-entity>
      </entity>
    </fetch>

    Hope this helps.

  • KrissWatts Profile Picture
    on at

    Thanks, Ravi. Works perfectly.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans