I have a list with a multiple people column (name it Members).
I want to update item's column to add a user to it. But it have to keep all users already in the item's column. I want to do so using JavaScript.
So far, I have :
function addUser() {
var clientContext = new SP.ClientContext(siteUrl);
var list = clientContext.get_web().get_lists().getByTitle('MyList');
var listItem= list.getItemById(listItemID);
var newMembers = oldMembers + newUser;
listItem.set_item('Members',newMembers);
listItem.update();
clientContext.load(listItem);
clientContext.executeQueryAsync(console.log("ok."), console.log("ko."));
}
newUser contains id and loginName like: 1#;i:0#.f|membership|[email protected]
In oldUser, i would like to have all user already in the field.
To do so, i wanted to use this:
var oldMembers = listItem.get_item("Members");
But I keep having this error:
Uncaught Error: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Is there another way to add my new user at the end of my old users list?
Environment : SharePoint Online. I'm working on a display template for a search web part only for this list. Users should be able in one click to join an item.