Search code examples
dynamics-crmfetchxml

CRM retrieve records with Fetchxml on today minus n days


I need fetchxml condition operator to retrieve all my appointments on today-11 days. I mean if I run my query today(12/04/2018) I want to retrieve my created records on 01/04/2018. If I run on 13/04/2018 - records created on 02/04/2018. Which operator can I use to get what I need?

<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">
  <entity name="appointment">
        <attribute name="subject"/>
        <attribute name="statecode"/>
        <attribute name="scheduledstart"/>
        <attribute name="scheduledend"/>
        <attribute name="createdby"/>
        <attribute name="regardingobjectid"/>
        <attribute name="activityid"/>
        <attribute name="instancetypecode"/>
        <order descending="false" attribute="subject"/>
        <filter type="and">
           <condition attribute="createdon" value="" operator=""/>
       </filter>
 </entity>


Solution

  • There is no straight operator for this. You have to use eq operator & calculate the expression (-11) yourself if you are using this fetchxml query in SSRS report @date:

    <condition attribute="new_date" operator="eq" value="@date"></condition>
    

    Or calculate in javascript/C# & pass it to paramDate, if you are calling this in form script or server code:

    '<condition attribute="new_date" operator="eq" value="' + paramDate + '"></condition>'