2

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.
1
  • after searching for ... unfortunately hours... this question and the answer from @Wedge really saved my day in the end
    – D M
    Commented Mar 20, 2020 at 13:45

2 Answers 2

6

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
2
  • Unfortunately now I get this error: 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.Int32' at position 96.
    – cAMPy
    Commented Nov 15, 2016 at 19:10
  • @cAMPy - must use new_lookupfield/Id and new_optionsetfield/Value to actually compare values of Lookups and OptionSets in the query (note the slash) Commented Jan 25, 2019 at 15:19
0

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)";

Not the answer you're looking for? Browse other questions tagged or ask your own question.