You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用OData过滤SharePoint API返回结果中的集合类型子元素

How to Filter SharePoint API Results for Collection(Edm.String) Fields Containing a Specific Value

Your initial filter expression $filter=Audience/ eq "Agent" won't work because Audience is a collection type (Collection(Edm.String)), not a single string value. You can't directly compare a collection to a single string—instead, you need to use OData's any operator to check if at least one element in the collection matches your criteria.

Correct Filter Syntax

Use this expression to retrieve items where the Audience collection contains the value "Agent":

$filter=Audience/any(a: a eq 'Agent')

Breakdown of the Expression

  • Audience/any(): This tells the API to iterate over each element in the Audience collection.
  • a: A placeholder alias for each element in the collection (you can use any valid identifier here, like item or val instead of a).
  • a eq 'Agent': The condition to check—does the current element equal the string "Agent"? If even one element in the collection meets this condition, the item is included in the results.

Example Full API Request

Here's how the full request would look when fetching items from a SharePoint list:

GET https://your-sharepoint-site-url/_api/web/lists/getbytitle('YourTargetList')/items?$filter=Audience/any(a: a eq 'Agent')

Validation with Your Sample Data

Looking at your provided XML response, the Audience collection includes <d:element>Agent</d:element>, so this item would be correctly returned by the filter above.

If you ever need to check for multiple values (e.g., items that include both "Agent" and "Internal"), you can chain multiple any conditions with and:

$filter=Audience/any(a: a eq 'Agent') and Audience/any(a: a eq 'Internal')

内容的提问来源于stack exchange,提问作者Stanislav Mozolevskiy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 21:37:41