Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Can anyone help me to get the user info from a person column using javascript? So far I have been able to read the list item and return a SP.FieldUserValue from which I can get a numeric Id (not sure what this ID is) and the display name. e.g.

var ManVal  = oListItem.get_item("RecruitingManager").get_lookupValue();
var ManId   = oListItem.get_item("RecruitingManager").get_lookupId();

How do I take this one step further to create a sp user object?

Ultimately what I'm trying to achieve is to retrieve the details from the list and then populate a people editor.

share|improve this question

1 Answer

The person field (actually called "people picker") has a specific JavaScript function which you might find useful: GetAllUserInfo()

There is a nice article on MSDN: How to: Use the client-side People Picker control in apps for SharePoint

The relevant code is:

// Get the people picker object from the page.
var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;

// Get information about all users.
var users = peoplePicker.GetAllUserInfo();
var userInfo = '';
for (var i = 0; i < users.length; i++) {
    var user = users[i];
    for (var userProperty in user) { 
        userInfo += userProperty + ':  ' + user[userProperty] + '<br>';
    }
}
$('#resolvedUsers').html(userInfo);

// Get user keys.
var keys = peoplePicker.GetAllUserKeys();
$('#userKeys').html(keys);

So basically you have to cast your field to a SPClientPeoplePicker and can then use GetAllUserInfo to iterate over all users in the field.

share|improve this answer
Thanks but I think you have misunderstood. I'm retrieving the person value from a list item, not people picker. I've read the article you have listed. – Phillip Hill 11 hours ago
I did misunderstand, but your code especially get_lookupValue() should work: stackoverflow.com/questions/8892999/… – moontear 7 hours ago
Where I'm getting confused is, that look up value returns SP.FieldUserValue - $1A_1: 11 $2Z_1: "Phillip Hill" proto: Object How do I get a user object from this so I can for instance get the email address of that user? I can then use that to set the people picker. All I'm trying to do is get a user from a person column in a list ad populate the people picker with this person. I'm obviously missing something obvious. – Phillip Hill 4 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.