Javascript client object model : get value of person or group multi value field (need the username)
How to get value for a Person or Group field which is of multi value?
Below is my code:
var _Assigned = "";
if (appPendItem.get_item("Assigned").length > 0)
{
if (appPendItem.get_item("Assigned").length ==1)
{
_Assigned = appPendItem.get_item('Assigned').get_lookupValue();
}
if (appPendItem.get_item("Assigned").length >1)
{
for (var i = 0; i < appPendItem.get_item("Assigned").length; i++)
{
_Assigned = _Assigned + appPendItem.get_item("Assigned")[i].get_lookupValue() + ";";
}
}
}
I am getting error : Object doesn't support property or method 'get_lookupValue'
Please suggest how to do this.
Thanks
Below is my code:
var _Assigned = "";
if (appPendItem.get_item("Assigned").length > 0)
{
if (appPendItem.get_item("Assigned").length ==1)
{
_Assigned = appPendItem.get_item('Assigned').get_lookupValue();
}
if (appPendItem.get_item("Assigned").length >1)
{
for (var i = 0; i < appPendItem.get_item("Assigned").length; i++)
{
_Assigned = _Assigned + appPendItem.get_item("Assigned")[i].get_lookupValue() + ";";
}
}
}
I am getting error : Object doesn't support property or method 'get_lookupValue'
Please suggest how to do this.
Thanks
March 19th, 2014 2:02pm
May be you can try:
SPFieldUserValue val = new SPFieldUserValue(Web, properties.ListItem["person_field"] asstring);
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/49701a4d-7e7a-42a5-83b8-e3f15069c25b/how-to-retrieve-several-users-assigned-in-a-person-or-group-field-list?forum=sharepointdevelopmentlegacy
var id = val.User.Id;
Free Windows Admin Tool Kit Click here and download it now
March 19th, 2014 2:07pm
Thanks for the reply.
I need something on the client side.
Using Javascript so I think I cannot use SPFieldUserValue.
Please help
March 19th, 2014 2:18pm
I tired this code, works perfectly for me:
var itemId = 3;
var targetListItem;
function runCode() {
var clientContext = new SP.ClientContext();
var targetList = clientContext.get_web().get_lists().getByTitle('XYZ');
targetListItem = targetList.getItemById(itemId);
clientContext.load(targetListItem, 'Users');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var users = targetListItem.get_item('Users');
for(var i = 0; i < users.length; i++) {
var userValue = users[i];
console.log(userValue.get_lookupValue());
}
}
function onQueryFailed(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', runCode);
OutPut:
var itemId = 3;
var targetListItem;
function runCode() {
var clientContext = new SP.ClientContext();
var targetList = clientContext.get_web().get_lists().getByTitle('XYZ');
targetListItem = targetList.getItemById(itemId);
clientContext.load(targetListItem, 'Users');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var users = targetListItem.get_item('Users');
for(var i = 0; i < users.length; i++) {
var userValue = users[i];
console.log(userValue.get_lookupValue());
}
}
function onQueryFailed(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', runCode);
OutPut:
Free Windows Admin Tool Kit Click here and download it now
March 5th, 2015 7:56am
Hi,
Before calling the get_lookupValue() method using the browser developer tool inspect that object, expand that object and check whether that object has that method, try exploring other methods in that object using the developer tool.
Let us know if you need any further regarding this.
Thanks
Shakir
March 5th, 2015 8:42am