Multiple values filter in Query Expression & FetchXML - "In" operator
Views (3143)
This blog post is to talk about the two different query options - Query expression & FetchXML to filter with multiple values in the same attribute. Another Stack Overflow contribution lead to this post.
FetchXML:
The multi-values that has to be filtered in an attribute should be listed in <value> nodes.
Query Expression:
In this case, the multi-values has to be comma separated like shown below.
There are some alternate ways like this:
and this: (credit to fellow contributor Ankit)
FetchXML:
The multi-values that has to be filtered in an attribute should be listed in <value> nodes.
<filter type="and">
<condition attribute="myfilter_attribute" operator="in" >
<value>1</value>
<value>2</value>
</condition>
</filter>Query Expression:
In this case, the multi-values has to be comma separated like shown below.
QueryExpression q = new QueryExpression("account");
q.Criteria.AddCondition("new_text", ConditionOperator.In, new object[] { "value1", "value2" });There are some alternate ways like this:
q.Criteria.AddCondition("new_text", ConditionOperator.In, "value1", "value2");and this: (credit to fellow contributor Ankit)
IList texts = new List{"1","2","testing"};string joined = string.Join(",", texts);
QueryExpression query = new QueryExpression("account") { ColumnSet = new ColumnSet("primarycontactid", "new_text"), NoLock = false, Criteria = { Conditions = { new ConditionExpression() { AttributeName = "new_text", Operator = ConditionOperator.In, Values = { joined } } } } }
This was originally posted here.

Like
Report
*This post is locked for comments