Retrivemultiple QueryExoression results are differs from UI advanced find results RRS feed

  • General discussion

  • Hi Team,

    I am facing problem with QueryExpression while using Retrivemultiple. the results count is differs from advance find.

    Always the results for advanced find is correct but using Retrivemultiple request giving 1 record less. i have found that the query is having filter condition on date only field. 

    below is the code I have written where i am getting less records then the advance find. please suggest how to get all records falls on same date.



     public EntityCollection GetContractsForRenewal(IOrganizationService organizationService, int numberOfDays)
               EntityCollection contractCollection = new EntityCollection();

                   DateTime today = DateTime.Now.Date;                
                   DateTime nextDate = Convert.ToDateTime(today.AddDays(numberOfDays).ToShortDateString());
                   QueryExpression query = new QueryExpression();
                   query.ColumnSet = new ColumnSet(Contract.ContractId, Contract.ContractName, Contract.ContractStartDate, Contract.ContractEndDate, Contract.ContractStatus, Contract.ContractTemplateId, Contract.AccountId, Contract.OwnerId);
                   query.EntityName = Contract.SchemaName;
                   OrderExpression orderQuery = new OrderExpression();
                   orderQuery.AttributeName = Contract.ContractEndDate;
                   orderQuery.OrderType = OrderType.Descending;
                   //query.Criteria.AddCondition(Contract.ContractEndDate, ConditionOperator.NextXDays, numberOfDays);
                   query.Criteria.AddCondition(Contract.ContractEndDate, ConditionOperator.On, nextDate.ToString("MM-dd-yyyy"));
                   query.Criteria.AddCondition(Contract.ContractStatus, ConditionOperator.Equal, Contract.ActiveStatus);
                   //query.Criteria.AddCondition(Contract.OwnerId, ConditionOperator.Equal, user);
                   contractCollection = organizationService.RetrieveMultiple(query);
               catch (Exception ex)

               return contractCollection;

    The missing record having <samedate> 11:00:00 where for others having <samedate> 00:00:00



    Monday, November 3, 2014 4:52 AM

All replies

  • Hi,

    Your problem may be to do with the date format you're passing. Try:

    DateTime nextDate = Convert.ToDateTime(today.AddDays(numberOfDays).ToString("yyyy-MM-dd"));
    query.Criteria.AddCondition(Contract.ContractEndDate, ConditionOperator.On, nextDate);

    Regards, Saad

    Monday, November 3, 2014 6:26 AM
  • Hi Saad,

    it's a date only field but i found in the database the time also coming for some records as with the same date but the time is -1 hour.

    the record is missing in this case.


    Naveen dasari


    Monday, November 3, 2014 7:56 AM