BasicTasksApp/Scripts/App.js
// Create, update and delete list items
Create, update and delete list items
Create update and delete list items
function createListItem(resultpanel) {
    var clientContext;
    var oWebsite;
    var oList;
    var itemCreateInfo;
    clientContext = new SP.ClientContext.get_current();
    oWebsite = clientContext.get_web();
    oList = oWebsite.get_lists().getByTitle("Announcements");
    itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    this.oListItem.set_item("Title", "My New Item!");
    this.oListItem.set_item("Body", "Hello World!");
    this.oListItem.update();
    clientContext.load(this.oListItem);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, successHandler),
        Function.createDelegate(this, errorHandler)
    );
    function successHandler() {
        resultpanel.innerHTML = "Go to the <a href='../Lists/Announcements'>list</a> to see your new item.";
    }
    function errorHandler() {
        resultpanel.innerHTML = "Request failed: " + arguments[1].get_message();
    }
}
function createListItem ( resultpanel ) { var clientContext ; var oWebsite ; var oList ; var itemCreateInfo ; clientContext = new SP . ClientContext . get_current ( ) ; oWebsite = clientContext . get_web ( ) ; oList = oWebsite . get_lists ( ) . getByTitle ( "Announcements" ) ; itemCreateInfo = new SP . ListItemCreationInformation ( ) ; this . oListItem = oList . addItem ( itemCreateInfo ) ; this . oListItem . set_item ( "Title" , "My New Item!" ) ; this . oListItem . set_item ( "Body" , "Hello World!" ) ; this . oListItem . update ( ) ; clientContext . load ( this . oListItem ) ; clientContext . executeQueryAsync ( Function . createDelegate ( this , successHandler ) , Function . createDelegate ( this , errorHandler ) ) ; function successHandler ( ) { resultpanel . innerHTML = "Go to the <a href='../Lists/Announcements'>list</a> to see your new item." ; } function errorHandler ( ) { resultpanel . innerHTML = "Request failed: " + arguments [ 1 ] . get_message ( ) ; } }
Create, update and delete list items
Create update and delete list items