如何使用带有 rest api 的 JSOM 检索自定义用户配置文件属性。
因为我需要检索当前登录用户的员工成本中心(自定义属性),但下面的代码不起作用。
<script>
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
headers: { Accept: "application/json;odata=verbose" },
success: function (data) {
try {
// userDisplayName=data.d.DisplayName;
//AccountName = data.d.AccountName;
var properties = data.d.UserProfileProperties.results;
for (var i = 0; i < properties.length; i++) {
if (properties[i].Key == "Employee Cost Center") {
var CostCenter= properties[i].Value;
}
}
$('#Diviision').text(CostCenter);
} catch (err2) {
}
},
error: function (jQxhr, errorCode, errorThrown) {
alert(errorThrown);
}
});
</script>