Querying choice field in Sharepoint using rest
I got a list in Sharepoint 2010 with a choice column. The choices are checkboxes.
How do I query the choice column using the rest api?
I've tried using
http://sp2010/_vti_bin/listdata.svc/mylist?$filter=myChoicesColumn/xxx eq something
and then I get
No property 'xxx' exists in type 'System.Collections.Generic.IEnumerable`1[[Microso开发者_开发问答ft.SharePoint.Linq.DataServiceEntity, Microsoft.SharePoint.Linq, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]' at position 6.
What property should I use?
None of these answers will work for SP fields that are of type multiselect (i.e. fields represented as checkboxes).
If you try the following filter on a multiselect choice field called "Grouping" like this:
$filter=Grouping/Value eq 'My Value'
You will get the error:
{
"error": {
"code": "",
"message": {
"lang": "en-US",
"value": "No property 'Value' exists in type 'System.Collections.Generic.IEnumerable`1[[Microsoft.SharePoint.Linq.DataServiceEntity, Microsoft.SharePoint.Linq, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]' at position 9."
}
}
}
}
Maybe Value
isn't required? You still get an error. In SP 2013 the MSDN documentation states that querying a multiselect choice is not possible. So I can only assume that the same is true for the 2010 REST API, which is hardly documented at all.
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
You need single quotes around the value in the filter.
$filter=myChoicesColumn eq 'something'
I tried this successfully on O365 but the same thing should work in OnPrem too.
~SITE_URL/_api/web/lists/getbytitle('LISTNAME')/items?$filter=(FieldInternalName eq 'CHOICE1') or (FieldInternalName eq 'CHOICE2')
Use "and" instead of "or" according to your needs.
Not sure you already have solved this. However:
Suppose you have a Product list with a lookup field to a country. And you want to filter the result on Products from France and you don't want to filter by Country ID, then you can filter on the $expand property like this:
http://sharepoint/_vti_bin/ListData.svc/Product?$expand=Country&$filter=Country/Title eq 'France'
I've expanded the REST call with the Country list and then set the filter to Country/Title to 'France'
I just got this working for my requirements with the following.
http://sp2010/_vti_bin/listdata.svc/mylist?$filter=myChoicesColumn/Value%20eq'something'
For anyone still struggling with this in SharePoint 2010 (which uses the /_vti_bin/listdata.svc
endpoint and not SharePoint 2013 and above's /_api/web
), I was successfully able to filter on a single-selection choice field using ChoiceFieldNameValue
in the $filter
parameter instead of ChoiceFieldName/Value
.
Note the lack of a forward slash between the field name and the word Value
. Bizarrely, the $select
parameter still requires the /Value
as expected.
My successful endpoint URL looked like this:
_vti_bin/listdata.svc/ListName?$filter=(ChoiceFieldNameValue eq 'targettext')&$select=ChoiceFieldName/Value&$expand=ChoiceFieldName
Replace ListName
with the name of your list and ChoiceFieldName
with the display name of your field, in each case with spaces removed and possibly with a numerical suffix to avoid naming collisions, and replace 'targettext'
with the value against which you want to filter.
Just a shot:
Did you try
http://sp2010/_vti_bin/listdata.svc/mylist?$filter=myChoicesColumn contains something
精彩评论