2011-03-21 38 views
14

我在Sharepoint 2010中获得了一个列表,并带有一个选择列。选择是复选框。使用休息查询Sharepoint中的选择字段

如何使用其余api查询选择列?

我使用

http://sp2010/_vti_bin/listdata.svc/mylist?$filter=myChoicesColumn/xxx eq something 

尝试,然后我得到

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.

我应该使用什么属性?

+1

所以最后的答案是什么?我遇到了同样的问题! – Shreyas 2014-09-12 05:46:48

+0

当我在这方面得到答案时,我已经完成了我正在进行的项目。抱歉,我无法说出正确的解决方案。 – Ivar 2014-09-15 10:09:09

+0

'myChoicesColumn/Value'的作品 – WhiteHat 2015-12-17 20:24:45

回答

0

只是一个镜头:

你尝试

http://sp2010/_vti_bin/listdata.svc/mylist?$filter=myChoicesColumn contains something 
2

你需要围绕在过滤器值单引号。

$filter=myChoicesColumn eq 'something' 
1

不知道你已经解决了这个问题。但是:

假设您的产品列表中包含查找字段的国家/地区。 你想过滤来自法国产品的结果,你不想按国家ID进行过滤,然后你可以过滤在$扩展属性是这样的:

http://sharepoint/_vti_bin/ListData.svc/Product?$expand=Country&$filter=Country/Title eq 'France' 

我已经扩大了REST调用与国家列表,然后将过滤器设置为国家/标题为'法国'

6

这些答案都不适用于类型为多选的SP字段(即字段表示为复选框)。

如果尝试在多选选择字段中输入以下过滤器被称为“分组”是这样的:

$filter=Grouping/Value eq 'My Value'

您将得到错误:

{ 
    "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." 
     } 
    } 
} 
} 

也许Value不需要?你仍然有错误。在SP 2013中,MSDN文档指出,查询多选选项是不可能的。所以我只能假设对于2010 REST API也是如此,这几乎没有记录。

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

+5

做得好微软。实施一种新的API,它的前身更糟糕,而且不会记录缺点。 – Fergal 2013-10-14 12:26:25

1

我刚刚得到这个工作我有以下要求。

http://sp2010/_vti_bin/listdata.svc/mylist?$filter=myChoicesColumn/Value%20eq'something' 
2

我在O365上成功试过这个,但同样的事情也应该在OnPrem中工作。

~SITE_URL/_api/web/lists/getbytitle('LISTNAME')/items?$filter=(FieldInternalName eq 'CHOICE1') or (FieldInternalName eq 'CHOICE2') 

根据您的需要使用“和”而不是“或”。

+0

我可以确认这种方法也适用于本地2013。新的REST API的行为与2010年时代的OData ListData.svc不同。 – Goyuix 2017-06-20 22:48:18

0

对于任何仍与这的SharePoint奋力2010(使用/_vti_bin/listdata.svc端点和非SharePoint 2013及以上的/_api/web),我是能够成功地在该$filter使用ChoiceFieldNameValue一个 -selection选择字段进行筛选参数而不是ChoiceFieldName/Value

请注意字段名称与单词Value之间缺少正斜杠。奇怪的是,$select参数仍然需要/Value预期。

我成功的端点URL是这样的:

_vti_bin/listdata.svc/ListName?$filter=(ChoiceFieldNameValue eq 'targettext')&$select=ChoiceFieldName/Value&$expand=ChoiceFieldName 

与数字后缀,以取代ListName与你的清单,ChoiceFieldName与字段的显示名称的名称,在每种情况下删除空格和可能避免命名冲突,并用您要过滤的值替换'targettext'