3

For some reason updating person or group fields in sharepoint stopped working. This seems to happen only on SharePoint online as my on-prem version is working fine.

As soon as FieldUserValue value is added to the array i get this error when creating list item: "We couldn't find an exact match." It works if you pass a single FieldUserValue object.

I have checked and the field has "multiple users" option selected.

Here is the code example:

var arr = [];

var person = new SP.FieldUserValue();
person.set_lookupId(47);
var person2 = new SP.FieldUserValue();
person2.set_lookupId(58);

arr.push(person);
arr.push(person2);


  var clientContext = new SP.ClientContext.get_current();
  var oList = clientContext.get_web().get_lists().getByTitle('Test');

  var itemCreateInfo = new SP.ListItemCreationInformation();
  var oListItem = oList.addItem(itemCreateInfo);
  oListItem.set_item('Title', defaults.Title);
  oListItem.set_item('person', arr);
  oListItem.update();

  clientContext.load(oListItem);
  clientContext.executeQueryAsync(
      Function.createDelegate(this, this.onQuerySucceeded),
      Function.createDelegate(this, this.onQueryFailed)
  );


  function onQuerySucceeded() {
      alert('Item created: ' + oListItem.get_id());
  }

  function onQueryFailed(sender, args) {
      alert('Request failed. ' + args.get_message() +
          '\n' + args.get_stackTrace());
  }
2

I have found a solution. You have to use SP.FieldUserValue.fromUser('test1@test1.com').

Here is an example:

var user1 = SP.FieldUserValue.fromUser('test1@test1.com')
var user2 = SP.FieldUserValue.fromUser('test2@test2.com')
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', 'My New Item!');
oListItem.set_item('person', [user1 ,user2]);
oListItem.update();
-1

SP.FieldUserValue.fromUser works with LoginName as well, so options are not limited to email only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.