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 365 | Integration, Dataverse...
Answered

FetchXML returning items outside filter parameters

(2) ShareShare
ReportReport
Posted on by 8
Hi
I am trying to get all emails in our CRM instance to warehouse it, and trying to load it year by year.
My query is:
<fetch mapping="logical">
    <entity name="email" enableprefiltering="1">
        <attribute name="activityid"/>
       
        ...
       
        <link-entity name="systemuser" to="owninguser">
            <filter type="and">
                <condition attribute="createdon" operator="ge" value="2019-01-01" />
                <filter type="and">
                    <condition attribute="createdon" operator="le" value="2019-12-31" />
                </filter>
            </filter>
        </link-entity>
    </entity>
</fetch>
 
but I have also tried the following filters
1)
            <filter type="and">
                <condition attribute="createdon" operator="ge" value="2019-01-01" />
                <condition attribute="createdon" operator="le" value="2019-12-31" />
            </filter>
2)
            <filter type="and">
                <condition attribute="createdon" operator="in-fiscal-year" value="2019" />
            </filter>
3)
            <filter type="and">
                <condition attribute="createdon" operator="on-or-after" value="2019-01-01" />
                <condition attribute="createdon" operator="on-or-before" value="2019-12-31" />
            </filter>
 
but none of them return only emails created in 2019. They DO return - consistently - the same number of rows, with these properties:
 
What am I missing? I am at my wits end.
 
Thanks!
Categories:
I have the same question (0)
  • Verified answer
    Tom_Gioielli Profile Picture
    2,778 Super User 2025 Season 2 on at
    You are filtering emails by when the related user was created, rather than when the email was created.
     
    You need to move your date filter so that it is outside of the link-entity to the system user table. Below code uses copilot to fix.
     
    <fetch mapping="logical">
      <entity name="email" enableprefiltering="1">
        <attribute name="activityid" />
        ...
        <filter type="and">
          <condition attribute="createdon" operator="on-or-after" value="2019-01-01" />
          <condition attribute="createdon" operator="on-or-before" value="2019-12-31" />
        </filter>
    
        <link-entity name="systemuser" from="systemuserid" to="owninguser" alias="u">
          <!-- systemuser-specific filters go here, if any -->
        </link-entity>
      </entity>
    </fetch>
    
     
     
     
  • JR-13111356-0 Profile Picture
    8 on at
    Thank you, @Tom_Gioielli
     
    I'll give that a shot.
     
    Funny thing is that I asked Copilot for help on this and the code I used was provided by Copilot.
     
    I guess it's true what they say "We trained Copilot on your code in GitHub, and that is why it sucks" lol
  • Tom_Gioielli Profile Picture
    2,778 Super User 2025 Season 2 on at
    Yeah, sometimes Copilot is so close that it's hard to see where the issue is and then it just runs with it.
     
    Good luck, and hope everything works!

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 66 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans