"Error: The User Does Not Exist or is Not Unique" Solved in SharePoint

Hi All.

Today is a new issue and solution.

Issue: We were adding an item into a list using the JavaScript Object Model (JSOM). We have one field in the list of type UserMulti as in the following:

  1. <Field ID="{}"  
  2.        Name="Users"  
  3.        DisplayName="Users"  
  4.        Type="UserMulti"  
  5.        UserSelectionMode="PeopleOnly"  
  6.        Required="TRUE"  
  7.        Group="My Site Columns">  
  8. </Field>  
We need to submit the multiple users to the list.

The following is the code snippet (sample code snippet) we must add to the item in the list:
  1. // Get the people picker object from the page.  
  2. var peoplePickerUsers = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;  
  3. // Get user keys.  
  4. var keysUsers = peoplePickerUsers.GetAllUserKeys();  
  5. var users = new Array();  
  6.   
  7. var selectedUsers = keysUsers.split(';');  
  8. $.each(selectedUsers, function () {  
  9.    users.push(SP.FieldUserValue.fromUser(this));  
  10. });  
  11. var creationInfo = new SP.ListItemCreationInformation();  
  12. var listItem = list.addItem(creationInfo);  
  13. listItem.set_item("Title", “Title”);  
  14. listItem.set_item("Description", “Description”);  
  15. listItem.set_item("Users", users);  
  16.   
  17. listItem.update();  
  18. context.load(listItem);  
  19.   
  20. context.executeQueryAsync(success, fail);  
When we added one or two users to the preceding user field it was working very fine.

But when we were trying to add three users then we were getting the exception: “The user does not exist or is not unique…” with the following stack trace.

Exception

Solution:

This seems to be a strange issue since adding two users works but no more than two users.

After digging in more, I found that there is a property “Mult” that must be specified. According to MSDN:

Mult Optional Boolean. TRUE to allow a lookup field to contain multiple values. The default is FALSE.

So after setting this property the fields schema looks as:
  1. <Field ID="{}"  
  2.          Name="Users"  
  3.          DisplayName="Users"  
  4.          Type="UserMulti"  
  5.          UserSelectionMode="PeopleOnly"  
  6.          Required="TRUE"  
  7.          Group="My Site Columns"  
  8.   Mult="TRUE">  
  9.   </Field>  
After changing the field schema it started working like a charm.

Thanks!

Feel free to provide any relevant comments / feedback / suggestions.