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 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
    3,078 Super User 2026 Season 1 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
    3,078 Super User 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 53 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans