SharePoint REST 在单个 REST 查询中获取用户标题 [英] SharePoint REST Get User Title in a single REST query

查看:71
本文介绍了SharePoint REST 在单个 REST 查询中获取用户标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表,其中有一个人员和组"列.当我使用 REST 查询行时,我会在此列中列出用户 ID.

I have a list which has a "People and Group" column. when I query the rows using REST, I get user Ids listed in this column.

我发现这篇文章将帮助我将每个 id 转换为标题

I found this article which will help me in converting each id to a title

http://www.codeproject.com/Articles/692289/How-to-Get-Login-Name-and-Display-Name-using-Sha

但我想知道是否有一种方法可以通过单个 REST 调用获取用户标题(而不是先获取 ID,然后再进行一次调用以将 ID 转换为用户显示名称和登录名)

But I am wondering if there is a way in which I can get the user title by a single REST call (rather than first get the ID and then making another call to convert the ID into the user display name and the login name)

推荐答案

使用 $expand OData 运算符,您可以指定请求返回来自其他列表的投影字段和查找值.

Using $expand OData operator you can specify that the request returns projected fields from other lists and the values of lookups.

以下 REST 端点:

The following REST endpoint:

/_api/web/lists/getbytitle('Pages')/items(1)?$select=Author/Name,Author/Title&$expand=Author/Id

返回页面列表中Author列的TitleName

{
    "d": {
        "__metadata": {
            "id": "63b9e943-6398-4b6d-acc9-fc4f554f78df",
            "uri": "https://contoso.sharepoint.com/_api/Web/Lists(guid'be43ccf2-5ca7-4957-bf81-7cdc86744d9b')/Items(1)",
            "etag": "\"6\"",
            "type": "SP.Data.PagesItem"
        },
        "Author": {
            "__metadata": {
                "id": "8e4ad44e-f6f0-4dcc-92c6-78dc3d2c68af",
                "type": "SP.Data.UserInfoItem"
            },
            "Name": "i:0#.f|membership|username@contoso.onmicrosoft.com",
            "Title": "John Doe"
        }
    }
}

这篇关于SharePoint REST 在单个 REST 查询中获取用户标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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