Recently, I faced an issue in my Team site where the workflow history list consumed 96% of the space, and due to insufficient space, my Team site's performance became very poor.
When I tried to open the list, I got the following error.
“This view cannot be displayed because it exceeds the list view threshold (100000 items) enforced by the administrator”.
Due to the exceeded threshold limit, I couldn’t check how many items were there to delete. I even tried to create a new view but couldn't see more than 100,000 items as enforced by the administrator.

Then, I decided to use the REST API to get to know the total number of items, so I used the below-mentioned syntax on the browser.
https://sharepoint.com/_api/webs/lists/GetByTitle(“Workflow History”)/itemcount

Finally, I found there are more than 55 lakh items that need to be deleted. It’s a very huge count really but the problem is I don’t have access to the application server to perform PowerShell script.
So as my first attempt, I planned to create a JavaScript button event to remove the list items in a single click but unfortunately, it deleted only a few items at a time.
<input type="button" id="btnSubmit" value="Delete All Items"/>
<br/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function() {
bindButtonClick();
});
function bindButtonClick() {
$("#btnSubmit").on("click", function() {
deleteAllItemsFromList();
});
}
var clientContext;
var website;
var oList;
var cnt = 0;
function deleteAllItemsFromList() {
clientContext = SP.ClientContext.get_current();
website = clientContext.get_web();
oList = website.get_lists().getByTitle('ListName');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>3000</RowLimit></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(website);
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);
oListItemDel.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onDeleteSucceeded), Function.createDelegate(this, this.onDeleteFailed));
}
}
function onQueryFailed(sender, args) {
alert('Failed');
}
function onDeleteFailed(sender, args) {
alert('Failed');
}
function onDeleteSucceeded(sender, args) {
cnt = cnt + 1;
var waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Loading...', '', 100, 330);
setTimeout("location.reload(true);", 25000);
}
</script>



Join the conversation! Your thoughts help the community grow.