This blog will showcase how to read current user(Logged In User) profile properties using Rest API in SharePoint.
var uspURL= _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties";
$.ajax({
url: uspURL,
method: "GET",
headers: {
"Accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
},
success: function (data) {
var userProfileDetails = data;
var propertyKey="XYZ";
var PropertyValuePair = $.grep(userProfileDetails.d.UserProfileProperties.results, function (v) {
return v.Key === propertyKey;
});
var propertyValue = PropertyValuePair[0].Value
},
error: function (jqxr, errorCode, errorThrown) {
alert(jqxr.responseText);
}
});
No comments:
Post a Comment