Using filter expression to query multiple option set values

Back to Blog Listing

When searching via the CRM API there is sometimes the need to have a filter for multiple option set values.
i.e. where status = 1 OR status = 4

Standard QueryExpression does not allow for the concept of where X value OR Y value, it simply works with AND (where X value AND Y value). To apply further logical filters it is necessary to add a filterExpression to your QueryExpression. This filterExpression allows for different operators other than “AND” to be used.

An example of how to use this is as follows:

Dim query As New Query.QueryExpression(new_payment.EntityLogicalName)
query.ColumnSet = New Query.ColumnSet("columns")
query.Criteria.AddCondition("new_contact", Global.Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal, New System.Guid(ContactGUID))                           
Dim childFilter As FilterExpression = query.Criteria.AddFilter(LogicalOperator.Or)
childFilter.AddCondition("new_status", ConditionOperator.Equal, 1)
childFilter.AddCondition("new_status", ConditionOperator.Equal, 4)
query.Criteria.AddCondition("new_eventdelegate", Global.Microsoft.Xrm.Sdk.Query.ConditionOperator.NotNull)

About the Author

James CTwo is our blogging alter ego for the Dynamics CRM and Web experts here at C2. We have a passion for anything CRM, Web Design or Social Media. We love writing about it! Find us on YouTube & Twitter.

comments powered by Disqus

Our White Papers

Discover the content that matters to you on business transformation. Explore how you can drive customer engagement, empower your team, optimise your businesses and revolutionise your products with the next digital revolution. For more information visit our white paper library.


C2 Newsletter

Our newsletter is sent on a quarterly basis, offering detailed insights into all aspects of business transformation with Microsoft cloud technologies. We also promote upcoming events and special offers throughout the year. Sign up to get involved today.

Dynamics 365 Office 365 Power BI Silver Partner