Created
August 20, 2015 15:57
-
-
Save webknowledgezone/18ceef786e3ce37333dd to your computer and use it in GitHub Desktop.
Create List Item Using JavaScript Object Model (JSOM)
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 createListItem() { | |
| var clientContext = SP.ClientContext.get_current(); | |
| var website = clientContext.get_web(); | |
| var oList = website.get_lists().getByTitle('WebKnowledgeZone'); | |
| var itemCreateInfo = new SP.ListItemCreationInformation(); | |
| this.oListItem = oList.addItem(itemCreateInfo); | |
| oListItem.set_item('Title', 'My New Item!'); | |
| oListItem.update(); | |
| clientContext.load(oListItem); | |
| clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); | |
| } | |
| function onQuerySucceeded() { | |
| alert('Item created: ' + oListItem.get_id()); | |
| } | |
| function onQueryFailed(sender, args) { | |
| alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment