我需要从AD获取用户信息到我正在使用javascript填写的列表中。对于一些人,我使用SP服务,但现在我需要获得当前登录用户的地址(街道,城市,邮政编码),电话号码和电子邮件。我可以从SP服务功能SPGetCurrentUser获取电话号码和电子邮件,但该地址怎么样?有什么建议?非常感谢!
答案 0 :(得分:0)
使用Rest API并获得所需的属性:
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
method: "GET",
headers: { Accept: "application/json;odata=verbose" },
success: function (data) {
try {
//Get properties from user profile Json response
var properties = data.d.UserProfileProperties.results;
accountName = GetPropertyVal(properties, "AccountName");
Location = GetPropertyVal(properties, "SPS-Location");
SIP = GetPropertyVal(properties, "SPS-sipAddress");
$("[title='CurrentUser']").val(accountName);
} catch (err2) {
}
},
error: function (jQxhr, errorCode, errorThrown) {
}
});
function GetPropertyVal(properties, key) {
var value = "";
for (var i = 0; i < properties.length; i++) {
if (properties[i].Key == key) {
value = properties[i].Value;
break;
}
}
return value;
}