Skip to content

Instantly share code, notes, and snippets.

@RyanHirsch
Created June 24, 2013 15:25
Show Gist options
  • Save RyanHirsch/5850862 to your computer and use it in GitHub Desktop.
Save RyanHirsch/5850862 to your computer and use it in GitHub Desktop.
Get currentUser object and then append it to a multi user field from Javascript
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
ctx.executeQueryAsync(function() {
}, function() {
console.error('error');
});
var lists = web.get_lists();
ctx.load(lists);
ctx.executeQueryAsync(function() {
console.log('success');
}, function() {
console.log('error');
});
var multiuser = lists.getByTitle('multiuser');
var item = multiuser.getItemById(1);
ctx.load(multiuser);
ctx.load(item);
ctx.executeQueryAsync(function() {
console.log('success');
}, function() {
console.log('error');
});
var currentUserObject = web.get_currentUser();
ctx.load(currentUserObject);
ctx.executeQueryAsync(function() {
console.log('success');
}, function() {
console.log('error');
});
var currentUserValue = new SP.FieldUserValue();
currentUserValue.set_lookupId(currentUserObject.get_id());
var poc = item.get_item('POC');
poc.push(currentUserValue);
item.set_item('POC', poc);
item.update();
ctx.load(item);
ctx.executeQueryAsync(function() {
console.log('success');
}, function() {
console.log('error');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment