Tuesday, February 1, 2011

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 };

No comments:

Post a Comment

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...