Example of adding 'Or' and 'And' Operator in a CRM Query

We most of the time need one operator, either 'and' Or 'or.

But there are some queries we need to use both these in collaboration. Following example displays how this can be done.

ConditionExpression conditionExpression1 = new ConditionExpression("a", ConditionOperator.Equal, Val);
ConditionExpression conditionExpression2 = new ConditionExpression("b", ConditionOperator.Equal, Val);
ConditionExpression conditionExpression3 = new ConditionExpression("statuscode", ConditionOperator.Equal, 1);

//Adds the or operator conditions
FilterExpression filterExpression = new FilterExpression();
filterExpression.FilterOperator = LogicalOperator.Or;
filterExpression.Conditions = new ConditionExpression[] { conditionExpression1, conditionExpression2 };

//Adds the or operator condition with and Operator condition
FilterExpression filterExpression2 = new FilterExpression();
filterExpression2.FilterOperator = LogicalOperator.And;
filterExpression2.Conditions = new ConditionExpression[] { conditionExpression3 };
filterExpression2.Filters = new FilterExpression[] { filterExpression };


Popular posts from this blog

Error message “User does not have send-as privilege.” when sending emails programmatically in CRM 2011