2011-03-21 17 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'