I am trying to get the user profile picture url for a user using some JavaScript, I am querying a person and group field in a list and getting the use id via some CAML Query.
However the issue I am having is actually getting the pictureUrl, I currently have the following:
function loadUserData(){
SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', getUserProfile);
}
function getUserProfile(){
console.log("getting user profiles");
context = SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(context);
var propertyName = "PictureURL";
var targetUser = userid;
userProfileProperty = peopleManager.getUserProfilePropertyFor(targetUser, propertyName)
context.executeQueryAsync(onSuccess, onFail);
}
function onSuccess() {
var messageText = "userprofile property is " + userProfileProperty.get_value();
alert(messageText);
}
function onFail(sender, args) {
alert("Error: " + args.get_message());
}
The userid is set in a previous query and I can see that in the console this is being pulled back succesfully, however I have been unable to pull back the picture url as this currently appears to be coming back blank even though I have a profile picture.
Can anyone provide any help with this please.