Created
June 24, 2013 15:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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