Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

FetchXML linked entity filter based on parent entity

Posted on by Microsoft Employee

How can i create a fetchxml query where the linked entity is filtered based on the parent entity. see the bold, red condition below. How can I achieve that??

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' >
<entity name='entity1' >
<attribute name='entity1_primaryid' />
<link-entity name='entity2' from='entity2_relationshipfield' to='entity1_primaryid' 
link-type='outer' > <filter type='and' > <condition entityname='entity2' attribute='createddate' operator='eq'
value="enity1_datecreated"+5days /> </filter> </link-entity> </entity> </fetch>


  • Suggested answer
    ashlega Profile Picture
    ashlega 34,473 on at
    RE: FetchXML linked entity filter based on parent entity

    Hi Mudassar,

     +1 for Hemant, but you might try doing this:

    - Create a calculated field on the child entity (DATEDIFF between parent.createdOn and entity.createdOn)

    - In your fetchXml, add a condition for that new calculated field (equals 5)

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: FetchXML linked entity filter based on parent entity

    Mudassar Hassan,

    You can not compare two fields in fetch xml.

    Hemant

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: FetchXML linked entity filter based on parent entity

    I know the way to generate the fetchXML, but the question is can I used the parent attribute in the linked-entity value filter?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: FetchXML linked entity filter based on parent entity

    Hi,

    The easiest way is to create your exact query with "Advance find" and then download the fetchXML.

  • Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: FetchXML linked entity filter based on parent entity

    Hi Mudassar Hassa,

    You can't compare two fields in FetchXML you can compare with values.

    But you can assign 'enity1_datecreated' to a variable and then add 5day.

    it should be

    var dateCreated= //enity1_datecreated get the value + 5days

    Hope this helps you !

    Hemant

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,986 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans