locked
CRM issue in retrieving records based on Date condition RRS feed

  • Question

  • Hello Everyone,

    I need to retrieve records from crm based on date condition(eg: on or after '15/2/2015') using QueryExpression. I'm not getting all the records which appears in advanced find for the same condition.

    Can you please tell me, which time zone will be considered when we give date field in the condition.

    And how can I get the correct number of records as same as Advanced find results.

    Thanks.

    Saturday, May 16, 2015 5:08 AM

All replies

  • The timezone used will be the timezone of the user that executes the QueryExpression.

    You should get the same results for Advanced Find as you do with the QueryExpression - are you sorting the data in the same way, and are you using paging in the QueryExpression ?


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Sunday, May 17, 2015 4:14 PM
    Moderator
  • If passing a DateTime object into the expression it will use the local timezone of the computer running the code.

    Please See code below

    QueryExpression oQuery = new QueryExpression(fetchEntity);
    oQuery.ColumnSet = new ColumnSet(true);
    oQuery.Criteria = new FilterExpression(LogicalOperator.And);
    oQuery.Criteria.AddCondition(attName,ConditionOperator.OnOrAfter,new DateTime(2015,02,15));
    oQuery.PageInfo = new PagingInfo();
    oQuery.PageInfo.PageNumber = 1;
    
    bool hasMore = true;
    List<Entity>  fullList = new List<Entity>();
    while(hasMore)
                {
                    EntityCollection oCollection = ServiceProxy.RetrieveMultiple(oQuery);
                    fullList.AddRange(oCollection.Entities.ToArray());
                    hasMore = oCollection.MoreRecords;
                    oQuery.PageInfo.PageNumber += 1;
                }
    return fullList;



    Wednesday, May 20, 2015 1:13 PM
  • Thank you. But still I have a question. With local time zone, how will it compare with the date of the records and filter it?

    • Edited by NithyaPalanisamy Monday, May 25, 2015 1:01 PM corrected the question
    Monday, May 25, 2015 1:00 PM