Reputation: 235
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[[Microsoft.SharePoint.Linq.DataServiceEntity, Microsoft.SharePoint.Linq, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]' at position 6.
What property should I use?
Upvotes: 16
Views: 21490
Reputation: 1
I have to get the data from the Choice field using the lookup column. I followed the following tutorial to resolve the issue.
The hint is simple create a new Calculated Column and copy the data from the original choice column to the newly created column. Now you can get the newly created column instead of the choice column.
Please follow this article: https://www.sharepointdiary.com/2017/03/sharepoint-lookup-on-choice-field.html#:~:text=Using%20choice%20fields%20as%20the,fields%20on%20any%20other%20list!
Upvotes: 0
Reputation: 7059
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.
Upvotes: 2
Reputation: 173
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.
Upvotes: 3
Reputation: 3210
I just got this working for my requirements with the following.
http://sp2010/_vti_bin/listdata.svc/mylist?$filter=myChoicesColumn/Value%20eq'something'
Upvotes: 1
Reputation: 1861
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
Upvotes: 7
Reputation: 19
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'
Upvotes: 1
Reputation: 6859
You need single quotes around the value in the filter.
$filter=myChoicesColumn eq 'something'
Upvotes: 2
Reputation: 2053
Just a shot:
Did you try
http://sp2010/_vti_bin/listdata.svc/mylist?$filter=myChoicesColumn contains something
Upvotes: 0