Last active
March 7, 2016 15:59
-
-
Save IAMIronmanSam/51a8745d56b3bc4976ed to your computer and use it in GitHub Desktop.
Create list item using CSOM
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
| 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