I have a People Picker column in my SharePoint List.
I need to get all the values (names) from this column. I am using Java script code to get the data from SharePoint lists.
My code is as below:
Here “User” is the name of the column in the list.
var enumerator = listItem.getEnumerator();
while (enumerator.moveNext()) {
var _User = "";
if (colListItem.get_item(User) !== 'undefined' && colListItem.get_item(User) !== null) {
//Check if people picker contains more than one value
if (colListItem.get_item(User).length > 0) {
//Check if people picker contains only one value
if (colListItem.get_item(User).length == 1) {
_User = colListItem.get_item(User)[0].$2e_1;
}
//Check if people picker contains more than one value
if (colListItem.get_item(User).length > 1) {
for (var i = 0; i < colListItem.get_item(User).length; i++)
{
//Append all User names with a semi colon separator
_User = _User + colListItem.get_item(User)[i].get_lookupValue() + ";";
}
_User.trim;
}
}
}
}
}
I know I need to use the get_lookupValue for this.
But If there is a single value in the people picker column, I am getting it as colListItem.get_item(User)[0].$2e_1;
I figured out that I need to use $2e_1
, using developer tools.
Is this the right way?
Is there any other better way?
Please suggest some articles , informative links on this as I am very new to sharepoint and also client side object model.
Thanks in advance.
A clear solution is explained here-
http://gocodin.blogspot.in/2017/04/how-to-get-lookup-valueusername-from.html
My way of getting value _User = colListItem.get_item(User)[0].$2e_1;
is wrong.
Users can be retrieved using get_lookupvalue
.
Hope this helps all those who are new to sharepoint and facing similar issue.
Thanks!