When you got special characters in REST API URI for GET, they cause error.
Use encodeURIComponent to encode the special characters
var userProfUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+encodeURIComponent("i:0e.t|pingfedratests|userId@company.com")+"'"
NWF$.ajax({
url: userProfUrl,
type: "GET",
headers: { "accept": "application/json;odata=verbose" },
success: function (data) {
//var userDisplayName = data.d.DisplayName;
var properties = data.d.UserProfileProperties.results;
var firstName;
var lastName;
for (var i = 0; i < properties.length; i++) {
var property = properties[i];
if (property.Key == "FirstName") {
firstName = property.Value;
}
if (property.Key == "LastName") {
lastName = property.Value;
}
}
NWF$('#' + txtUserFullName).val(firstName + ' ' + lastName);
},
error: function () {
alert("Error getting User Full Name!");
}
});
No comments:
Post a Comment