Sharepoint - How can I filter based on Choice fields when using ListData.svc in SharePoint 2010?

Choice fields are returned with a Value without the need for expansion:

Example: IP_WorkflowStatus = IP_WorkflowStatusValue

Here is an example of a query without using expansion:

$filter=IP_WorkflowStatusValue eq '2-Validated'

If you want to use expansion, then you need to use expanded field notation Relation/Field:

$filter=IP_WorkflowStatus/Value eq '2-Validated'&$expand=IP_WorkflowStatus

It is not supported for multiselect fields (i.e. fields represented in the normal UI as check boxes). The following quote is for 2013 but the same rules apply for the ListData.svc. You can filter on the client side, though, depending on how you represent the data and the controls you use.

Queries for multi-value lookup fields and users

Because multi-value lookup fields are returned as a string of multiple values, there is no way to query for them (for example, the equivalent of an Includes element or NotIncludes element is not supported).

http://msdn.microsoft.com/en-us/library/fp142385(v=office.15).aspx


Retrieve choice field value in Rest API by attaching 'value' to the field name. for e.g. if your field name is Flags, use the term FlagsValue in the filter string. This works if the choice field is not a multi select field.

Your url should be like

http://tssites/departments/appdev/_vti_bin/ListData.svc/TeamCalendar?$expand=Flags&$filter=FlagsValue eq 'PTO'

There is another work around for this issue. Create a calculated column and add the Choice field as formula for it. Now use the calculated column for filtering.

For Multiselect Choice fields:

Follow the below steps.

  1. Add a new text column by name FlagsCSV
  2. Edit the editform of the list item and add a content webpart to it. Hook an html page to the content webpart. (Let the name of html page be content.html and upload this to libraries like SiteAssests)
  3. Edit the content.html and use jquery to add a change events to the options of Flags. Generate comma separated values of the multiple items selected Flag options and set it to the textBox of FlagsCSV.
  4. Save and close html page. Now every time you edit the list item, FlagsCSV will also gets updated.
  5. You may use the FlagsCSV field for your filtering later in your rest call.

Tags:

Odata