Created
February 27, 2017 02:38
-
-
Save PatD/89252c051e1b143f0c7e3e299dc31e1b to your computer and use it in GitHub Desktop.
SharePoint Create List Item with JavaScript. Shows response w/SP.UI.Notify
This file contains 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 that creats a list item. | |
// Expects a title and category to be passed to it. | |
function createListItem(titleText,categoryText) { | |
// Where are we in SharePoint? | |
var _clientContext = SP.ClientContext.get_current(); | |
// SharePoint List name | |
var _talkList = _clientContext.get_web().get_lists().getByTitle('list name'); | |
var itemCreateInfo = new SP.ListItemCreationInformation(); | |
var _talkListItem = _talkList.addItem(itemCreateInfo); | |
_talkListItem.set_item('Title', titleText); | |
_talkListItem.set_item('Status', categoryText); | |
_talkListItem.update(); | |
_clientContext.load(_talkListItem); | |
_clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed); | |
}; | |
function onQuerySucceeded() { | |
// Use built-in notification | |
SP.UI.Notify.addNotification('New Item Created...', false); | |
console.log("New item created"); | |
} | |
function onQueryFailed(sender, args) { | |
SP.UI.Notify.addNotification('Error creating list item, check console', true); | |
console.log('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