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 :
Customer experience | Sales, Customer Insights,...
Answered

FetchXML - Not Exists Not Working

(0) ShareShare
ReportReport
Posted on by 240

I've tried this a few different ways, trying to find someone who donated "Last Year", but not "This Year".

Not that it matters, but dates used for last year= 7/1/2020 to 6/30/2021, and date used for this year = 7/1/2021 to 6/30/2022.

Just trying to figure out the best way to do this when there are underlying "conditions" on both sides to the same entity.

Method one (Returns Rows, but includes people that donated in both years, along with those that didn't in some cases, not all, weird):

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="contact">
     <attribute name="contactid" />
     <attribute name="fullname" />
     <attribute name="emailaddress1" />
     <filter type="and">
          <condition attribute="statecode" operator="eq" value="0" />
          <condition entityname="aa" attribute="altai_fr_donationid" operator="not-null" />
          <condition entityname="bb" attribute="altai_fr_donationid" operator="null" />
     </filter>
     <link-entity name="altai_fr_donation" from="altai_contactid" to="contactid" link-type="outer" alias="aa">
          <attribute name="altai_fr_donationid" />
          <attribute name="altai_collecteddate" />
          <attribute name="altai_collectedamount" />
          <filter type="and">
               <condition attribute="altai_collecteddate" operator="on-or-after" value="@lfystartdate" />
               <condition attribute="altai_collecteddate" operator="on-or-before" value="@lfyenddate" />
          </filter>
     </link-entity>
     <link-entity name="altai_fr_donation" from="altai_contactid" to="contactid" link-type="outer" alias="bb">
          <attribute name="altai_fr_donationid" />
          <filter type="and">
              <condition attribute="altai_collecteddate" operator="on-or-after" value="@tfystartdate" />
              <condition attribute="altai_collecteddate" operator="on-or-before" value="@tfyenddate" />
          </filter>
      </link-entity>
</entity>
</fetch>

Method Two (Returns 0 rows always):

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='contact' >
     <attribute name='contactid' />
     <attribute name='fullname' />
     <attribute name='emailaddress1' />
     <filter type='and' >
          <!-- Contact In Active State -->
          <condition attribute='statecode' operator='eq' value='0' />
          <!-- LAST FISCAL YEAR - Donation in Active State, Donation EXISTS, On or after start selected, on or before end selected -->
          <condition entityname='lfy' attribute='statecode' operator='eq' value='0' />
          <condition entityname='lfy' attribute='altai_fr_donationid' operator='not-null' />
          <condition entityname='lfy' attribute='altai_collecteddate' operator='on-or-after' value='@lfystartdate' />
          <condition entityname='lfy' attribute='altai_collecteddate' operator='on-or-before' value='@lfyenddate' />
          <!-- THIS FISCAL YEAR - Donation in Active State, Donation DOES NOT EXIST, On or after start selected, on or before end selected -->
          <condition entityname='tfy' attribute='statecode' operator='eq' value='0'/>
          <condition entityname='tfy' attribute='altai_fr_donationid' operator='null' />
          <condition entityname='tfy' attribute='altai_collecteddate' operator='on-or-after' value='@tfystartdate' />
          <condition entityname='tfy' attribute='altai_collecteddate' operator='on-or-before' value='@tfyenddate' />
     </filter>
     <link-entity name='altai_fr_donation' from='altai_contactid' to='contactid' link-type='outer' alias='lfy'>
     </link-entity>
     <link-entity name='altai_fr_donation' from='altai_contactid' to='contactid' link-type='outer' alias='tfy'>
     </link-entity>
</entity>
</fetch>

I have the same question (0)
  • Suggested answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi John Klemetsrud,

    I think this is not possible with one query, maybe I am wrong.

    Step #1: You need to retrieve donors who donated last year.

    Step#2: You need to retrieve donors who contributed this year

    Step#3: On the basis of these two queries you have your results

    Let me know if I can you more details.

  • Verified answer
    Adam Murabito Profile Picture
    30 on at

    One approach would be to retrieve Donations instead of Contacts.

    Consider the following dataset - in your use case, we'd want to return Randall and Jalen, because they donated last year but not this year, and exclude Donovan:

    pastedimage1655218532305v1.png

    You can achieve this by querying for donations in last fiscal year, and then joining the donations table back on the Contact. Your join will look for donations in this fiscal year. From there, you can filter and only include results where this fiscal year's donation date is null.

      
        
        
        
          
          
            
            
          
        
        
          
            
            
          
          
        
      
    

    Executing this fetch gives the following result, which we can tell corresponds to Randall and Jalen from the LFY donation dates:

    pastedimage1655219270685v2.png

  • jklemetsrud Profile Picture
    240 on at

    This is exactly what I needed, a fresh set of eyes on it. I miss the water cooler sometimes!! I was thinking about it from the contact side as my starting point rather than the donation side. Thankfully the client did want all the individual donation information listed and this works perfectly. Much Thanks!

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans