web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Multiple values filter in Query Expression & FetchXML - "In" operator

Arun Vinoth Profile Picture Arun Vinoth 11,615 Moderator
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.

<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.

Comments

*This post is locked for comments