locked
Plugin QueryExpression with daterange filter RRS feed

  • Question

  • CRM2016

    I am reading an XML file which has a date string formatted as yyyy-mm-dd

    I need to use a query expression to look up a record which has that date or date past 

    ie if the datetsting is 2016-10-05 I need to return the record from the 05/10/2016 to current day

    I have tried the following

                            filter4.AddCondition(

    "new_submitteddate", ConditionOperator.GreaterEqual, DateTime.ParseExact(Right(strProcessingDate, 2) & "/"& Mid(strProcessingDate, 6, 2) & "/"& Left(strProcessingDate, 4), "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat))

    but I get the error  String was not recognized as a valid DateTime.


    Dont ask me .. i dont know


    • Edited by Pete Newman Tuesday, October 4, 2016 7:49 PM
    Tuesday, October 4, 2016 7:47 PM

Answers

All replies

  • Hi Pete,

    Can you check the below link for the solution, looks like a similar issue.

    https://social.microsoft.com/Forums/en-US/8e967ed0-b676-430d-b316-54405a06ff3b/condition-expression-with-date-time?forum=crmdevelopment

    ConditionExpression condition1 = new ConditionExpression();
     condition1.AttributeName = "new_submitteddate";
     condition1.Operator = ConditionOperator.GreaterEqual;
     condition1.Values = new object[] { "2009-11-02T03:00:25-05:00" };

    Hope this helps!!!

    Thanks,

    Prasad

    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    • Edited by Prasad Parameswaran Tuesday, October 4, 2016 9:09 PM Added link and Code block
    • Marked as answer by Pete Newman Tuesday, October 4, 2016 9:25 PM
    Tuesday, October 4, 2016 8:48 PM
  • Hi,

    Thank you for your help,

    Looking at that example, showed me that my code was correct, just my logic wasn't

    The strProcessingDate is always either going to be the same as new_submitteddate, or a few days afterwards. What I was trying to say was return records where new_submitteddate was => strprocessingdate, which is not the case, its the other way round. strpocessing date should be => new_submittedate.

    Just need to work out how to code that in now as a condition. I don't want to put in new_submitteddate <= strprocessingdate because that could return upwards of 1000 records


    Dont ask me .. i dont know

    Tuesday, October 4, 2016 9:30 PM