Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 610
Tschareck Avatar asked Jan 09 '23 01:01

Tschareck


2 Answers

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.

like image 186
Alex Avatar answered Jan 11 '23 15:01

Alex


In latest version (July 2020), the feature to compare the two attributes of same entity is available in Query Expression (SDK), fetchxml and web api. Read more

This code creates a condition to return only records where the first and last names are the same

new ConditionExpression("firstname", ConditionOperator.Equal, true, "lastname");
like image 38
Arun Vinoth - MVP Avatar answered Jan 11 '23 15:01

Arun Vinoth - MVP