{"id":4566,"date":"2015-07-28T11:57:05","date_gmt":"2015-07-28T11:57:05","guid":{"rendered":"http:\/\/ngenioussolutions.com\/blog\/?p=108"},"modified":"2026-02-11T07:28:42","modified_gmt":"2026-02-11T07:28:42","slug":"bulk-delete-sharepoint-list-items-using-csom","status":"publish","type":"post","link":"https:\/\/ngenioussolutions.com\/blog\/bulk-delete-sharepoint-list-items-using-csom\/","title":{"rendered":"Bulk delete SharePoint List items using CSOM"},"content":{"rendered":"<p><em>SharePoint CSOM enables us to delete bulk list items using browser console.<\/em><\/p>\n<p align=\"justify\"><strong>Scenario-1<\/strong>: \u00a0We have a list of records to be deleted from a SharePoint list and we do not want to delete record one by one.<\/p>\n<p align=\"justify\"><strong>Scenario-2<\/strong>: \u00a0We want to delete the list and list already had cross the threshold limit and not allowing to delete list until records reaches under the threshold limit.<\/p>\n<p>Following script demonstrates the steps to achieve the same<\/p>\n<p><strong>Step-1<\/strong>: \u00a0Navigate to SharePoint site where list is present.<\/p>\n<p><strong>Step-2<\/strong>: Open Inspect Element by clicking F12 in any browser. Open console tab.<\/p>\n<p><strong>Step-3<\/strong>: Copy and Paste following code in console, Insert the list name (wherever &#8216;ListName&#8217; is mentioned) and run the command.<\/p>\n<p>\/\/\u00a0&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p><em>var clientContext;<\/em><br \/>\n<em> var website;<\/em><br \/>\n<em> var oList;<\/em><br \/>\n<em> var cnt = 0;<\/em><br \/>\n<em> \/\/ Make sure the SharePoint script file &#8216;sp.js&#8217; is loaded before your code runs.<\/em><br \/>\n<em> SP.SOD.executeFunc(&#8216;sp.js&#8217;, &#8216;SP.ClientContext&#8217;, sharePointReady);<\/em><\/p>\n<p><em>\/\/ Create an instance of the current context.<\/em><br \/>\n<em> function sharePointReady() {<\/em><br \/>\n<em> clientContext = SP.ClientContext.get_current();<\/em><br \/>\n<em> website = clientContext.get_web();<\/em><br \/>\n<em> oList = website.get_lists().getByTitle(&#8216;ListName&#8217;);<\/em><\/p>\n<p><em>var camlQuery = new SP.CamlQuery();<\/em><br \/>\n<em> camlQuery.set_viewXml(&#8216;1000&#8217;);<\/em><br \/>\n<em> this.collListItem = oList.getItems(camlQuery);<\/em><\/p>\n<p><em>clientContext.load(website);<\/em><br \/>\n<em> clientContext.load(collListItem, &#8216;Include(Id)&#8217;);<\/em><br \/>\n<em> clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));<\/em><br \/>\n<em> }<\/em><\/p>\n<p><em>function onQuerySucceeded(sender, args) {<\/em><\/p>\n<p><em>var listItemInfo = &#8221;;<\/em><br \/>\n<em> var listItemEnumerator = collListItem.getEnumerator();<\/em><\/p>\n<p><em>while (listItemEnumerator.moveNext()) {<\/em><br \/>\n<em> var oListItem = listItemEnumerator.get_current();<\/em><br \/>\n<em> var ID = oListItem.get_id();<\/em><br \/>\n<em> var oListItemDel = oList.getItemById(ID);<\/em><br \/>\n<em> oListItemDel.deleteObject();<\/em><br \/>\n<em> clientContext.executeQueryAsync(Function.createDelegate(this, this.onDeleteSucceeded), Function.createDelegate(this, this.onDeleteFailed));<\/em><br \/>\n<em> console.log(ID + &#8221; : Deleted&#8221;);<\/em><br \/>\n<em> }<\/em><br \/>\n<em> }<\/em><\/p>\n<p><em>function onQueryFailed(sender, args) {<\/em><br \/>\n<em> console.log(&#8216;Request failed. &#8216; + args.get_message() + &#8216;\\n&#8217; + args.get_stackTrace());<\/em><br \/>\n<em> }<\/em><\/p>\n<p><em>function onDeleteFailed(sender, args) {<\/em><br \/>\n<em> console.log(&#8216;Delete failed. &#8216; + args.get_message() + &#8216;\\n&#8217; + args.get_stackTrace());<\/em><br \/>\n<em> }<\/em><\/p>\n<p><em>function onDeleteSucceeded(sender, args) {<\/em><br \/>\n<em> cnt = cnt + 1;<\/em><br \/>\n<em> console.log(&#8216;Delete success : &#8216; + cnt);<\/em><br \/>\n<em> }<\/em><\/p>\n<p>\/\/\u00a0&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p><strong>Note<\/strong>: Above script delete 1000 records at a time.<\/p>\n<div style=\"background-color: #efefef; margin-top: 30px; padding: 20px 30px; text-align: left; border-radius: 3px;\">\n<p><span style=\"font-size: 18px; font-weight: 500;\">Related Article:<\/span><\/p>\n<ul style=\"font-size: 21px;\">\n<li><a href=\"https:\/\/ngenioussolutions.com\/blog\/how-to-update-sharepoints-group-owner-using-powershell\/\">How to update SharePoint\u2019s Group Owner using PowerShell<\/a><\/li>\n<li style=\"margin-top: 10px;\"><a href=\"https:\/\/ngenioussolutions.com\/blog\/get-extract-of-files-modified-after-particular-date-from-sharepoint-library-or-folder-within-library-powershell-script\/\">Get extract of files modified after particular date from SharePoint library or folder within library (PowerShell script)<\/a><\/li>\n<li style=\"margin-top: 10px;\"><a href=\"https:\/\/ngenioussolutions.com\/blog\/blog-delete-all-sharepoint-list-item-using-powershell\/\">Delete all sharepoint list item using powershell<\/a><\/li>\n<li style=\"margin-top: 10px;\"><a href=\"https:\/\/ngenioussolutions.com\/blog\/window-scroll-event-is-not-firing-in-sharepoint\/\">Window scroll event is not firing in SharePoint<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>SharePoint CSOM enables us to delete bulk list items using browser console. Scenario-1: \u00a0We have a list of records to be deleted from a SharePoint&#8230;<\/p>\n","protected":false},"author":1,"featured_media":8587,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[210],"tags":[],"class_list":["post-4566","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-sharepoint-blogs"],"menu_order":0,"_links":{"self":[{"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4566"}],"version-history":[{"count":6,"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4566\/revisions"}],"predecessor-version":[{"id":12486,"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4566\/revisions\/12486"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/media\/8587"}],"wp:attachment":[{"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ngenioussolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}