简体   繁体   English

无法使用 REST api 获取查找字段值

[英]Unable to fetch lookup field values using REST api

I am using REST api to fetch data from a SharePoint list.我正在使用 REST api 从 SharePoint 列表中获取数据。

I am able to get the lookup fields data using this query: requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department .我可以使用此查询获取查找字段数据: requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department

However when I use this query requestUri = "/_api/lists/GetByTitle('Data')/items(6)" or this query requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department&$filter=ID eq 6" I am not getting the data from the lookup fields.但是,当我使用此查询requestUri = "/_api/lists/GetByTitle('Data')/items(6)"或此查询requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department&$filter=ID eq 6"我没有从查找字段中获取数据。

What could be going wrong here?这里可能出了什么问题?

I tested with the endpoint, it works:我测试了端点,它有效:

/_api/web/lists/GetByTitle('ListName')/items(1)?$select=ID,Title,Department/Title&$expand=Department

在此处输入图像描述

Compared the url with yours in original question, only append web behind /_api, it should be working.比较原始问题中的 url 和你的,/_api 后面只有 append web,它应该可以工作。

The issue was found.问题已找到。

Figured out that I was fetching an item for which all the lookup fields were blank.发现我正在获取一个所有查找字段都是空白的项目。

I fetched another item, and data was returned as expected.我取了另一个项目,数据按预期返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM