3
votes

I'm doing this simple query inside a plugin:

QueryExpression query = new QueryExpression(hb_aula.EntityLogicalName);
query.ColumnSet = new ColumnSet(true);

query.Criteria = new FilterExpression(LogicalOperator.And);
query.Criteria.Conditions.Add(new ConditionExpression("hb_datafim", ConditionOperator.NotOn, DateTime.Now));

EntityCollection ent = service.RetrieveMultiple(query);

Where I'm trying to retrieve all hb_aula records in which hb_datafim date field is not on today (or some other specific date, DateTime.Now is just an example).

When I execute this I get the error

Unknown Condition Operator: NotOn.

Am I doing anything wrong or is this an unfinished CRM 2011 feature?

1
Why not just use a less then 00:00 this morning (so convert DateTime.Now to date only at 00:00 and use that)?AdamV
It looks good to me. Are you getting the error any ru. Time or compile time?Daryl
AdamV I'm not looking for workarounds I want to know why I can't use that specific operator. If it can't be used why is it there? And to simulate the same operator I would need always two conditions one for less than and other for greater than, and would still have the time part issues.Daryl I get the error at runtime.budahead

1 Answers

2
votes

I did some testing around your use case and got the same result. It looks like this was possibly unfinished in the SDK. I'd recommend using the following workaround -

DateTime today = DateTime.Now;
DateTime yesterday = today.AddDays(-1);
DateTime tomorrow = today.AddDays(1);
FilterExpression filter = new FilterExpression(LogicalOperator.Or);
filter.AddCondition("createdon", ConditionOperator.OnOrBefore, yesterday);
filter.AddCondition("createdon", ConditionOperator.OnOrAfter, tomorrow);
QueryExpression query = new QueryExpression("contact")
    {
        ColumnSet = new ColumnSet(true),
        Criteria = filter
    };

EntityCollection ent = service.RetrieveMultiple(query);