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 CRM (Archived)

FetchXML - not in last x fiscal years

(0) ShareShare
ReportReport
Posted on by 215

I am trying to build a custom fetch query that will return the accounts that have recently become "active" by our internal description not in Dynamics status terms. We are an educational facility and thus we have a custom "Sessions" entity instead of a sales entity and this entity holds a "Start Date/Time" field and companies that hire us are "Clients" that I'm using for the fetchxml.

This is my goal:

  • Only show accounts that have had a session with a start "date/time" This Fiscal Year but have had no related session with a start "date/time" in the last 2 Fiscal Years.

Is there a "not in" version of the "last X Fiscal Year" that can be achieved in FetchXML?

Here's the basic filter that I'm starting with but I need the "last-x-fiscal-years" line to be "not in"

    <filter type="and">
      <condition attribute="statecode" operator="eq" value="0" />
    </filter>
    <link-entity name="new_session" from="new_client" to="accountid" alias="aa">
      <filter type="and">
        <condition attribute="new_startdatetime" operator="this-fiscal-year" />
        <condition attribute="new_startdatetime" operator="last-x-fiscal-years" value="2" />
        <condition attribute="statuscode" operator="ne" value="794540005" />
      </filter>
    </link-entity>


Thanks

*This post is locked for comments

I have the same question (0)
  • DevCrm16 Profile Picture
    215 on at
    RE: FetchXML - not in last x fiscal years

    Thank you! That appears to have done it. Thank you for the resource.

  • Verified answer
    ashlega Profile Picture
    34,477 on at
    RE: FetchXML - not in last x fiscal years

    Hi,

      you might try this:

    <filter type="and">
    <condition attribute="statecode" operator="eq" value="0" />
    <condition attribute="new_sessionid" entityname="aa" operator="null"/>
    <condition attribute="new_sessionid" entityname="bb" operator="not-null"/>
    </filter>
    <link-entity name="new_session" from="new_client" to="accountid" alias="aa" link-type="outer">
      <filter type="and">
        <condition attribute="new_startdatetime" operator="last-x-fiscal-years" value="2" />
       <condition attribute="statuscode" operator="ne" value="794540005" />
      </filter>
    </link-entity>
    <link-entity name="new_session" from="new_client" to="accountid" alias="bb" link-type="outer">
      <filter type="and">
        <condition attribute="new_startdatetime" operator="this-fiscal-year" />
        <condition attribute="statuscode" operator="ne" value="794540005" />
      </filter>
    </link-entity>

    For the explanations, check this out:

    http://www.itaintboring.com/dynamics-crm/two-most-ignored-features-of-fetchxml/

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans