cAMPy
cAMPy

Reputation: 587

Dynamics CRM Odata query filter by optionsetvalue

How do I filter records by optionset value? I am trying like this:

 "$select=new_id&$filter=new_campaignid/Id eq guid'" + myId+ "' and new_optionsetfield eq '" + optionsetCode + "'"

But this does not work. I keep on getting bad request with error message:

Operator 'eq' incompatible with operand types 
'Microsoft.Crm.Metadata.ComplexTypeInstance`1[[Microsoft.Xrm.Sdk.OptionSetValue, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]' 
and 'System.String' at position 96.

Upvotes: 2

Views: 5286

Answers (2)

D M
D M

Reputation: 320

One of my filters for Dynamics CRM 365 (on premise) looks like this

var filter = "(substringof('SomeStringValue', Description) eq false) and (StatusCode/Value ne 1)";

Upvotes: 0

Wedge
Wedge

Reputation: 887

I'm pretty sure this is what you need:

"$select=new_id&$filter=new_campaignid/Id eq guid'" + myId+ "' and new_optionsetfield/Value eq " + optionsetCode

Edited: Removed the quotes, because that is an int value, not a string

Here's an exact working sample:

AccountSet?$filter=CustomerTypeCode/Value eq 1

Upvotes: 6

Related Questions