Clean up List History in SharePoint Online

Hello, today I have one super trick to clean up lists in SharePoint online.

If you have any list in the SharePoint online which exceeded the limit of 5000 items and now you can no longer see the items or apply filters and groupings:

  1. Navigate to SharePoint site where list is present, for example, https://domain/sites/PWA
  2. Open Inspect Element by clicking F12 in any browser and open console tab.
  3. Copy and Paste following code in the console, inform the ListName (Display Name not Internal Name) and if you prefer to reduce the RowLimit. (The max is 5.000)


var clientContext;
var website;
var oList;
var cnt = 0;
// Make sure the SharePoint script file ‘sp.js’ is loaded before your code runs.
SP.SOD.executeFunc(‘sp.js’, ‘SP.ClientContext’, sharePointReady);

// Create an instance of the current context.
function sharePointReady() {
clientContext = SP.ClientContext.get_current();
website = clientContext.get_web();
oList = website.get_lists().getByTitle(‘ListName‘);

var camlQuery = new SP.CamlQuery();
this.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem, ‘Include(Id)’);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

function onQuerySucceeded(sender, args) {

var listItemInfo = ”;
var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var ID = oListItem.get_id();
var oListItemDel = oList.getItemById(ID);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onDeleteSucceeded), Function.createDelegate(this, this.onDeleteFailed));
console.log(ID + ” : Deleted”);

function onQueryFailed(sender, args) {
console.log(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
function onDeleteFailed(sender, args) {
console.log(‘Delete failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());

function onDeleteSucceeded(sender, args) {
cnt = cnt + 1;
console.log(‘Delete success : ‘ + cnt);


You can run this code as many times as necessary.

I hope you liked!

#ProActive  #JoinUs

Diego Pereira

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog do Project

Tudo que você queria saber sobre Microsoft Project, Project Server e Project Online


by Allan Rocha

Paul's Project Server and Project Online Blog

Microsoft Project Server and Project Online (PPM)

%d bloggers like this: