Sunday, September 6, 2015

Delete a list items using JavaScript library code in SharePoint 2013

Would like to delete 13000+ records from the list in SPO.
SCRIPT  BEGIN
var itemId;
var oListItem;
 $(document).ready(function() {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

    });

function sharePointReady(){
    var clientContext = new SP.ClientContext("XXX");
    var oList = clientContext.get_web().get_lists().getByTitle('Workflow History');
for LOOP
{
    this.oListItem = oList.getItemById(itemId);
    oListItem.deleteObject();

    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed)
    );
}
}
SCRIPT END
https://msdn.microsoft.com/en-us/library/office/jj163201.aspx#BasicOps_SPListItemCRUD

No comments: