Search code examples
c#dynamics-crmquery-expressions

CRM ConditionExpression to compare two attributes


I'm using Microsoft CRM SDK to retrieve entities. I'm writing QueryExpression with FilterExpression.

How to write a condition, that takes two attributes in consideration? I want to retrieve entities, for which attribute "Export Date" is less than "Modified On". (ie. all that have been modified since last export).

QueryExpression query = new QueryExpression();
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.Or;

ConditionExpression condition = new ConditionExpression();
// ...
//how to write this condition? 

filter.AddCondition(condition);

Solution

  • When querying CRM, the following restrictions apply:

    • The left-hand side of conditions must be a CRM attribute
    • The right-hand side of conditions must be a constant

    In other words, attributes can't be compared directly in a single query.

    As a rule of thumb, if your QueryExpression can be built as Advanced Find then you're okay, otherwise you're most likely going to need intermediate queries.