How to retrieve the custom user profile properties using JSOM with rest api.
As i need to retrieve Employee Cost Center(Custom property) of current login user but the below code is not working.
<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>