【问题标题】:Inserting a user into a person field in sharepoint using the rest api使用 rest api 将用户插入 sharepoint 中的人员字段
【发布时间】:2015-11-21 15:10:41
【问题描述】:
【问题讨论】:
标签:
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);
}
});
}