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

查看:93
本文介绍了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

How to filter by lookup field value using SharePoint REST

Assume a Contacts list that contains a lookup field named Province

选项1

将查找列添加到列表时,其ID可以通过REST自动访问.例如,将名为Province的字段添加到列表中时,可以设置或通过列表项的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>

其中<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>

其中<ProvinceTitle>是省份Title

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

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