Skip to content

Instantly share code, notes, and snippets.

@IAMIronmanSam
Last active March 7, 2016 15:59
Show Gist options
  • Select an option

  • Save IAMIronmanSam/51a8745d56b3bc4976ed to your computer and use it in GitHub Desktop.

Select an option

Save IAMIronmanSam/51a8745d56b3bc4976ed to your computer and use it in GitHub Desktop.
Create list item using CSOM
function createItemCSOM(listName){
var context = SP.ClientContext.get_current(); //gets the current context
var web = context.get_web();
var list = web.get_lists();
var targetList = list.getByTitle(listName);
var listItemCreation = new SP.ListItemCreationInformation();
var newItem = targetList.addItem(listItemCreation);
newItem.set_item("owner",SP.FieldUserValue.fromUser('alias@domain.com'));
newItem.update();
context.load(newItem);
context.executeQueryAsync(function(){
console.log("Newly created item ID"+newItem.get_id());},
function(){
console.log("Something went wrong");
});
};
function ItemCreationFail(sender, args){
console.log(args.get_message());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment