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

Fetch XML query

(0) ShareShare
ReportReport
Posted on by 8

I'm creating a console app in C# that runs every night - it fires a query and then starts a workflow against the returned records

One of my conditions is that the Effective-To date field is equal or less than today's date 

I can't find a way of putting Today's date as a variable, so every time it runs it uses that days date as today

So the below is what im trying to achieve

<condition attribute="effectiveto" operator="on-or-before" value="TODAY" />

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I'm afraid you will have to pass value as DateTime.Now.ToString("yyyy-mm-dd"). Can you provide bigger piece of code?

  • G.Vetere Profile Picture
    8 on at

    This is my query:

    string getQuotes = @"

               <fetch mapping = 'logical' distinct = 'false'>

                   <entity name = 'quote'>

                       <attribute name = 'name'/>

                       <attribute name = 'statecode'/>

                       <attribute name = 'quoteid'/>

                       <filter type = 'and'>

                           <condition attribute = 'statecode' operator= 'eq' value = '1'/>

                           <condition attribute = 'statuscode' operator= 'not-in'>

                               <value>200000014</value>

                               <value>5</value>

                               <value>200000013</value>

                           </condition>

                           <condition attribute='effectiveto' operator='on-or-before' value='TODAY'/>

                       </filter>

                   </entity>

               </fetch>";

  • Verified answer
    G.Vetere Profile Picture
    8 on at

    Ok, I sorted it, thanks

    I added the variable:

    String todaysDate = DateTime.Now.ToString("yyyy-MM-dd");

    Then called it within the query:

    <condition attribute='effectiveto' operator='on-or-before' value='" + todaysDate + @"'/>


  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Use something like following:

    string getQuotes = $@"
    <fetch mapping = 'logical' distinct = 'false'>
    <entity name = 'quote'>
    <attribute name = 'name'/>
    <attribute name = 'statecode'/>
    <attribute name = 'quoteid'/>
    <filter type = 'and'>
    <condition attribute = 'statecode' operator= 'eq' value = '1'/>
    <condition attribute = 'statuscode' operator= 'not-in'>
    <value>200000014</value>
    <value>5</value>
    <value>200000013</value>
    </condition>
    <condition attribute='effectiveto' operator='on-or-before' value='{DateTime.Today:yyyy-MM-dd}'/>
    </filter>
    </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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans