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)

Linking multiple entities in one Fetch XML

(0) ShareShare
ReportReport
Posted on by

Hi,

I have a scenario where Entity A need to me linked to Entity B and it is one to many relationship. i.e one record in Entity A can have a relationship with n records in Entity B.
But I want to retrieve records from Entity B based on priority.

I want to retrieve A to B with B age as 20, if I don't find 20 I'll go with 30 and so on. 

Entity A
S.no
A1
A2

  Entity B  
Key Name Age
A1 X 20
A1 Y 30
A1 Z 40
A2 L 30
A2 M 40

From the above tables I want 
A1-X

A2-L

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    TylerS.Dev Profile Picture
    729 on at

    I suggest you download xrmtoolbox and use FetchXML builder for this.

    Below is fetchxml based on the fields that you given.

    <fetch>
      <entity name='Entity A' >
        <attribute name='S.no' />
        <link-entity name='Entity B' from='Key' to='S.no' link-type='inner' >
          <attribute name='Name' />
          <filter type='or' >
            <condition attribute='Age' operator='eq' value='20' />

            <condition attribute='Age' operator='eq' value='30' />
          </filter>
        </link-entity>
      </entity>
    </fetch>

    please mark as verified if this answers your question.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Or the other way around is making the code dynamic:

    <fetch>

     <entity name='Entity A' >

       <attribute name='S.no' />

       <link-entity name='Entity B' from='Key' to='S.no' link-type='inner' >

         <attribute name='Name' />

         <attribute name='Age' />

         <filter type='or' >

           <condition attribute='Age' operator="ge" value='20' />

         </filter>

       </link-entity>

     </entity>

    </fetch>

    Then on your code, you will get the Age attribute and doing your things (e.g check Age = 20, 30,.. etc).

  • manid Profile Picture
    10 on at

    Thanks Tyler,

    I tried in this way but I'm getting both the records.

    Like A1-X

          A1-Y

  • manid Profile Picture
    10 on at

    Thanks Temmy,

    I tried in that way but I'm getting two records like

    A1-X

    A-Y

    And I just gave age as an example but in my scenario Age is String not a number.

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