Power Automate Delete all items in SharePoint list

In this Microsoft flow or Power Automate tutorial, we will see how to bulk delete list items in SharePoint Online using Power Automate. Here is a detailed example on Power Automate delete all items in sharepoint list.

We will also see, how to delete SharePoint list items programmatically using JSOM or JavaScript object model as well as an example on SharePoint online pnp delete list items.

Power automate delete SharePoint list items

There will be a number of scenarios where you will want to delete all items from a SharePoint list. There are various ways we can delete all items from a list in SharePoint Online or SharePoint 2013, SharePoint 2016, or SharePoint 2019. Check out SharePoint 2016 vs SharePoint 2019.

Let us first check the steps to delete SharePoint list items using flow or Power Automate.

For this, I have created a SharePoint list and you can see there are a few items in the list. We will delete all items using flow.

power automate delete all items in sharepoint list
power automate delete all items in sharepoint list

Now, let us create the flow or Power Automate.

Go to https://india.flow.microsoft.com/ and then click on the + Create button from the left navigation.

power automate delete all items from sharepoint list
power automate delete all items from sharepoint list

Then it will show the three ways to make a flow in Office 365:

  • Start from blank
  • Start from a template
  • Start from a connector

Here select Instant cloud flow from Start from blank. You can select a Scheduled cloud flow or any other option.

You create an Instant cloud flow, then you can trigger manually from Power Automate mobile app. If you make a scheduled cloud flow, then you can trigger the flow on a scheduled basis.

But for this example, I will create an Instant cloud flow.

delete all items from sharepoint list power automate
delete all items from sharepoint list power automate

Then it will ask for a name and you have to select when to trigger this flow, here I have selected to Manually trigger a flow. In this case, you can see a flow button on Mobile. And I gave the name as “Delete All Items Flow”. Then click on the Create button.

delete all items from sharepoint list using flow
delete all items from sharepoint list using flow

Then the flow will get created and here click on + New step to add out flow logic to delete all items from the SharePoint list.

delete all items from sharepoint list flow
delete all items from sharepoint list flow

Here search for get items and then add the Get Items SharePoint flow action like below:

how to delete all items from sharepoint list using flow
how to delete all items from sharepoint list using flow

Now, configure the Get items flow action. Choose the SharePoint Online site name where your list is presented. Then it will display all the lists presented under the SharePoint Online site. Here then choose the particular list from which you want to delete all the items.

how to delete all items from sharepoint list using power automate
how to delete all items from sharepoint list using power automate

Once you have all the list items, we need to iterate over it by using the Apply to each control. Search for Apply to each and add it to the flow.

how to delete all items from sharepoint list
how to delete all items from sharepoint list

Then it will ask for “Select an output from previous steps“, here choose value. Once you put the cursor, it will display.

power automate delete all items in sharepoint list
power automate delete all items in sharepoint list

Then inside Apply to each, click on Add an action. Then it will add an action inside it.

power automate delete sharepoint list item
power automate delete sharepoint list item

Here, we need to delete items from the SharePoint Online list. Search for Delete item and add Delete item SharePoint action. This will take the item id and will delete the item.

power automate delete all rows in sharepoint list
power automate delete all rows in sharepoint list

Here we need to configure the Delete item action. Here provide the Site Address (Select the SharePoint site URL), List Name (Select the list name) and then in Id provide the ID of the List item like below:

sharepoint list delete all items
sharepoint list delete all items

Now Save the flow and now, we can test the flow. Here after saving the flow, click on Test button like below:

sharepoint 2013 bulk delete list items
sharepoint online bulk delete list items

Then it will ask you to test whether Manually and Automatically. Here choose Manually.

delete sharepoint list items programmatically
delete sharepoint list items flow

Then you can click on Run flow button like below:

sharepoint delete all items from list
sharepoint delete all items from list

Once the flow run successfully, you can see a message like below:

power automate delete sharepoint online list items
power automate delete sharepoint online list items

And if you see the Flow history, green tick mark will appear in all the steps. If there will be any issues, then it will show the error here.

power automate delete sharepoint list items
power automate delete sharepoint list items

Now, when you will open the SharePoint Online list, you will see all the SharePoint list items.

power automate how to delete sharepoint list items
power automate how to delete sharepoint list items

Anytime you can click on the My flows and you will be able to see all the flows. From here also, you can select the flow and click on the Run button like below:

delete all items from sharepoint list power automate
delete all items from sharepoint list power automate

If you are using flow mobile app, then you will see a button and on click on the button, the flow will trigger.

This is how to delete all items from SharePoint list using Power Automate.

I have also created a video tutorial on how to delete all items from sharepoint list using power automate.

Delete SharePoint list items programmatically using JSOM

Now, let us see, how to delete all items from the SharePoint list programmatically javascript object model (jsom) in SharePoint Online.

In SharePoint Online we can only use client-side object model code, we can not use any server-side code.

In this particular example, we got a requirement to delete all items from a SharePoint online list using the JavaScript object model (jsom).

Here we are using a SharePoint online site Office 365 but the same code will also work for SharePoint 2016 and SharePoint 2013.

In this jsom example I have taken a button and on click of that button it will delete all items from a list known as “SourceList”. And I have added the jsom code inside a script editor web part which we have put inside a web part page in SharePoint Online.

If you are new to JSOM (JavaScript Object Model), then you can download a FREE PDF Of 51 JSOM Examples in SharePoint Online.

Here in the CAML query, we are passing the RowLimit as 100, you can provide as per the requirement.

Delete all items from SharePoint list programmatically javascript client object model (jsom)

Below is the full JavaSctipt Object model code to delete all items from the sharepoint list programmatically.

<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('SourceList');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>100</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;
alert('Delete success : ' + cnt);
}
</script>

Once you will save the code and click on the button to delete, it will display an alert on each item delete like below:

delete all items from list using jsom sharepoint
SharePoint Online Delete all items from list using jsom

Here, we saw, how to delete all items from sharepoint list programmatically javascript or jsom in SharePoint Online or SharePoint 2019/2016/2013.

SharePoint pnp delete all list items

Now, let us see how to all list items using PnP in SharePoint Online. The same pnp code we can use to delete list items from SharePoint 2013, SharePoint 2016 and SharePoint 2019.

If you are new to pnp SharePoint Online, read SharePoint Online Development using Patterns and Practices (PnP).

SharePoint online pnp delete list items

On my SharePoint Online site, I have a list name called “Order Details” with few items. We will see how we can delete all items from this SharePoint Online list programmatically using PnP core CSOM library code.

sharepoint online pnp delete list items
sharepoint online pnp delete list items

The below references we have to use in the code to work with PnP libraries:

  • Microsoft.SharePoint.Client
  • OfficeDevPnP.Core

Here I have created an asp.net application and I have added a button. Just click on the button, it will Delete all items from the list of SharePoint Online using the PnP core CSOM library.

<div>
<asp:Button ID="btnDeleteItems" runat="server" Text="Delete Items From the List" OnClick="btnDeleteItems_Click" /><br />
<asp:Label ID="lblDeleteItems" runat="server" Text=""></asp:Label>
</div>

Below given snippet code is delete all items from the list of SharePoint online using PnP.

AuthenticationManager authMgr = new AuthenticationManager();
string siteURL = https://DomainName.sharepoint.com/sites/TSInfoPNP";
string userName = "*******@DomainName.onmicrosoft.com";
string password = "******";
protected void btnDeleteItems_Click(object sender, EventArgs e)
{
deleteItemsInList();
}
void deleteItemsInList()
{
try
{
using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteURL, userName, password))
{
List oList = ctx.Web.GetListByTitle("Order Details");
ctx.ExecuteQueryRetry();
CamlQuery query = CamlQuery.CreateAllItemsQuery(4000);					Microsoft.SharePoint.Client.ListItemCollection items = oList.GetItems(query);
ctx.Load(items);
ctx.ExecuteQuery();
for (int i = items.Count - 1; i >= 0; i--)
{
items[i].DeleteObject();
}
ctx.ExecuteQuery();
lblDeleteItems.Text = "All Items Deleted from the List Successfully";
}
}
catch (Exception ex)
{
}
}

		

Run your application and click on button on the page.

Delete all items from the SharePoint list programmatically using PnP core CSOM Library
sharepoint online pnp delete list items

Go and check your SharePoint Online list all the items are deleted as shown below.

pnp delete all list items
pnp delete all list items

Here, we learned, how to delete all items programmatically from list of SharePoint Online using PnP core CSOM Library. Here, we see an example on SharePoint online pnp delete list items.

You may like the following SharePoint tutorials:

In this SharePoint tutorial, we learned, how to delete SharePoint list items. Different ways to delete SharePoint list items:

  • Delete all items from SharePoint list Power Automate
  • Delete SharePoint list items programmatically using JSOM
  • Delete list items in SharePoint Online using PnP
>