Tarun D

Tarun D

  • NA
  • 1.3k
  • 114.8k

Insert Multiple values for Person/Group Field using JSOM

Jul 25 2016 8:17 AM
I am creating a sharpeoint hosted app.  I am uisng client side people picker control and  trying to insert multiple user values in the Person/Group Field(Supervisor) and Getting this error "The user does not exist or is not unique." Below is my code, This code is working fine for single user and fails for multiple users . Can anyone help  please..
 
var list = web.get_lists().getByTitle("StudentDetails");
var listCreationInformation = new SP.ListItemCreationInformation();
var listItem = list.addItem(listCreationInformation);
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;
// Get information about all users.
var users = peoplePicker.GetAllUserInfo();
// Get user keys.
var keys = peoplePicker.GetAllUserKeys();
var finalusers = new Array();
for (var i = 0; i < users.length; i++) {
var arryuser = users[i];
finalusers.push(SP.FieldUserValue.fromUser(arryuser.Key));
}
listItem.set_item("Supervisor", finalusers);
listItem.update();
ctx.load(listItem);
 
 
Thanks in Advance 
 

Answers (4)