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

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

FetchXML returning items outside filter parameters

(0) ShareShare
ReportReport
Posted on by
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)
  • Suggested answer
    Tom_Gioielli Profile Picture
    2,454 Super User 2025 Season 2 on at
    FetchXML returning items outside filter parameters
    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>
    
     
     
     

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 77 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 57 Most Valuable Professional

#3
Anthony Blake Profile Picture

Anthony Blake 43 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans