SharePoint 2013 REST 如何选择查找字段并根据查找字段进行筛选? [英] SharePoint 2013 REST How to select a look up field and also filter based on look up field?

查看:17
本文介绍了SharePoint 2013 REST 如何选择查找字段并根据查找字段进行筛选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在我的 SharePoint 2013 列表中选择查找字段.我也无法根据查找字段进行过滤.

I can't select look up field in my SharePoint 2013 List. also I can't filter base on a Look up field.

例如我有名称测试列表,这个列表有字段:标题、公司、省公司和省是查找字段我想根据省是查找字段进行过滤使用 REST 查询会出错:

for example I have List with Name Test and this list has fields: Title, Company, Province the Company and Province is look up fields I want to filter based on Province which is a look up field using REST query it gives error:

我的查询:

https://TestServer/sites/AIB/OBC/_api/web/lists/getByTitle('Test')/items?$select=Province/Title&$expand=Province&$filter=Province/Title eq 'ABC'

当我将 URL 放入我的浏览器进行测试时它给出错误它给出了打击错误:

it gives error when I put the URL in My browser for testing it gives the blow error:

<m:message xml:lang="en-US">The field or property 'Province' does not exist.</m:message>

如何根据 SharePoint 2013 REST 中的查找字段进行过滤?

How to filter based on a look up field in SharePoint 2013 REST ?

推荐答案

如何使用 SharePoint REST 按查找字段值过滤

假设一个 Contacts 列表包含一个名为 Province

选项 1

当一个查找列被添加到列表中时,它的 ID 可以通过 REST 自动访问.例如,将名为Province 的字段添加到List 时,可以通过List Item 的ProvinceId 属性设置或获取Province Id.

When a lookup column is being added into list, its ID become accessible automatically via REST. For example, when the field named Province is added into List, Province Id could be set or get via ProvinceId property of List Item.

以下查询演示了如何通过查找字段 ID(在我们的示例中为 Province Id)过滤列表项:

The following query demonstrate how to filter list items by lookup field Id (Province Id in our case):

/_api/web/lists/GetByTitle('<list title>')/items?$filter=LookupField eq <ProvinceId>

其中 是省份 ID

选项 2

为了按查找值过滤,查询应包含$expand查询选项以检索投影字段(如Province Title).以下示例演示了如何按查找字段值(在我们的示例中按 Province Title)过滤:

In order to filter by lookup value, the query should contain $expand query option to retrieve projected fields (like Province Title). The following example demonstrates how to filter by lookup field value (by Province Title in our case):

/_api/web/lists/GetByTitle('Contacts')/items?$select=Province/Title&$expand=Province&$filter=Province/Title eq <ProvinceTitle>

其中是省份的Title

这篇关于SharePoint 2013 REST 如何选择查找字段并根据查找字段进行筛选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆