【问题标题】:Inserting a user into a person field in sharepoint using the rest api使用 rest api 将用户插入 sharepoint 中的人员字段
【发布时间】:2015-11-21 15:10:41
【问题描述】:

我正在尝试使用工作流中的其余 api 更新远程共享点站点中的列表项。我在理解如何填充人员字段时遇到问题。我在网上查看并读到您应该使用用户的 id 而不是登录名,但是如果我不知道用户 id 怎么办?我可以从哪里得到这个?

我一直在阅读以下链接,但它没有解释 id 的来源

how to add user to sharepoint list item user field using REST api in sp2013?

【问题讨论】:

标签: sharepoint sharepoint-2013


【解决方案1】:

您将能够使用此 REST 调用查看所有 UserProfile 属性:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\user'

要获取特定属性(在本例中为 UserProfileGUID),请使用:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='UserProfile_GUID')?@v='domain\user'

如果您使用的是 CSOM,这可能会对您有所帮助: The proper way to write a SharePoint User to a User Field in a SharePoint list

我过去曾使用 CSOM (js) 和 SSOM (powershell) 成功完成此操作。

【讨论】:

    【解决方案2】:

    我知道这有点晚了,但是对于任何寻找如何获取用户 ID 的答案的人来说,请使用以下函数

    function getUserId(userName) {
    
        $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers?$select=Id&$filter=Title eq '" + userName + "'",
            type: 'GET',
            headers: {
                "Accept": "application/json;odata=verbose"
            },
            success: function (data) {
                return data.d.results[0].Id;
            },
            error: function (error) {
                console.log(error);
            }
        });
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多