문제

I have a list that I'm trying to query using ListData.svc. I am trying to pull back records within a date range and with a particular value from a Choice field checked. If I use Lists.asmx, I can build the CAML query to pull back the records I need, but I want to use ListData.svc for this solition. I am able to filter on columns whose values are stored in the list and I am using "$expand" to pull back the data for my Choice field, but I don't know how to structure the OData URI to filter based on the choice field.

I'm trying a query like this:

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

The error I am getting back is:

Operator 'eq' incompatible with operand types 'System.Collections.Generic.IEnumerable`1[[Microsoft.SharePoint.Linq.DataServiceEntity, Microsoft.SharePoint.Linq, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]' and 'System.String' at position 6.

Thanks for your assistance.

도움이 되었습니까?

해결책

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

다른 팁

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

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.

Simple.. If you want to filter a choice field with name "color" just give like this:

$filter=colorValue eq 'blue'&$expand=color

Just append Value with column name. here colorValue

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top