Get People Picker Field Value from SharePoint List – JSOM

Following is the JSOM code which will help in getting single or multiple items from a SharePoint’s People Picker Field.

function GetPeoplePickerFieldValue(currentListItem, internalFieldName) {
    if (currentListItem.get_item(internalFieldName) !== 'undefined' && currentListItem.get_item(internalFieldName) !== null) {
        if (currentListItem.get_item(internalFieldName).length > 0) {
            var _user = "";
            //If field has only one item
            if (currentListItem.get_item(internalFieldName).length == 1) {
                _user = currentListItem.get_item(internalFieldName)[0].get_lookupValue();
                if (_user == null)
                    _user = "";
            }
            //If field has multiple item
            if (currentListItem.get_item(internalFieldName).length > 1) {
                for (var i = 0; i < currentListItem.get_item(internalFieldName).length; i++) {
                    //Append all User names with a semi colon separator
                    _user = _user + currentListItem.get_item(internalFieldName)[i].get_lookupValue() + "; ";
                }
                _user.trim;
                if (_user == null)
                    _user = "";
            }
        }
        return _user;
    }
}

Source: Microsoft TechNet Forum


Comments

  1. Thanks for this code. It is really helpful. I had explored a lot to get this code. Thanks a lot once again.

Leave a Reply

Your email address will not be published / Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.