Jaa


How to cleanup large Workflow History list in Office 365

 

Recently, on our team site we had misbehaving workflow, which created over 18 million rows in the Workflow History list. Needles to say it consumed bunch of space on our site and caused other issues.

It was not as easy to clean this up, as one would hope. When I tried to delete the offending list I got this error:

image

 

Next, I tried to contact our technical support team. Technician informed me that they can’t delete offending list either, they just recently had the same issue with different customer and their recommendation is to manually delete list entries using tabular list view to get bellow 5000 items threshold. Sad smile

With 18 million rows in my Workflow History list, that would be lots of clicking. Winking smile

I decided to write simple console application to delete rows in the Workflow History list using SharePoint CSOM.

Basically, there are four simple steps to accomplish this task:

  1. Open connection to your o365 site
  2. Set credentials
  3. Get list
  4. Batch delete items in the list
Partial code snippet

 

You will find default batch size set to 250 items in my project. From my testing, making batch size smaller or larger just decreased performance. This was sweet spot for me. In my run, I averaged 850 deleted items per minute. You can test your own processing performance and adjust batch size accordingly.

You can download compiled console application from my OneDrive and you can start deleting items in no time.  Run the application by using following command:

deleteworkflowhistory.exe “[yoursiteurl]” “[List Name]” “[User Name]” “[Password]”

Make sure to replace tokens with your own values. If you do not use startup parameters you will be prompted by the application to enter values for each parameter.

If you like to dig little deeper, complete source code for this project is available on my OneDrive as well.

I hope you will find this project useful and it will save you some time while trying to delete items from large lists.

 

Cheers,

Comments

  • Anonymous
    September 28, 2014
    Hi Ivan, first of all, thank you for sharing this solution. im facing a very similar issue with the workflow history. when I run your code I get the following error: Could not load file or assembly 'Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified. Resuming run do you have any idea on how to fix it, I already searched for it on google but I can only find info for SP 2010

  • Anonymous
    September 28, 2014
    The comment has been removed

  • Anonymous
    September 29, 2014
    Hi Ivan, no I haven't yet, let me install it and let you know the results. Thanks

  • Anonymous
    September 29, 2014
    Ivan, it worked, it is now deleting the 600k items. thanks for your help.

  • Anonymous
    September 29, 2014
    Hello, The .exe is working fine at our end, however it's not deleting the items from Workflow History List, rather our items are getting increasing rapidly even no workflows are triggered on any list/library. We are giving the list name parameter as - "Workflow History"..Please suggest what could be the possible reason for such a behavior ?

  • Anonymous
    September 29, 2014
    @Vipul when you run exe do you get any messages in console? Something is writing to your Workflow History log. Can you read any some entries and identify source?

  • Anonymous
    September 29, 2014
    Does it effect, if we stop .exe while running ? Also, we are using site URL as : https://<server URL>/sites/ABC...Username and password is also correct...Why the items are increasing in Workflow History list ? :(

  • Anonymous
    September 29, 2014
    Hello Ivan, When we run your exe, console opens (cmd) and asks for parameters/agruments like "Enter Site URL", etc. After giving all 4 arguments, it starts..How I can check that something is writing to Workflow History Log. How can i read some entries and identify the source..Please guide !!! Also, does it effects if I close/stop the exe while running ?

  • Anonymous
    September 29, 2014
    @Vipul If you close console window application will stop. However, you can minimize it and let it run. depending on number of items in your list it will take some time. To check items in your Workflow History list open the list <your Url>/Lists/Workflow%20History/  and see what is there. If you can't open the list because there are too many items, create a list view with a filter to get bellow 5k items threshold.

  • Anonymous
    September 29, 2014
    Ivan, Thanks for the suggestion. However, now I can see that list items are getting reduced automatically even though no exe is running. Does it has anything to do with Workflow CleanUp Timer Job.?. Its very random, sometimes the items are increasing and sometimes (like at this point of time-midnight in India)  decreasing ..Trust me, no exe is running.. :( What could be the possible reason ?

  • Anonymous
    September 29, 2014
    Hi @Vipul, If you refer to the site /ME-20153 im deleting the items, please don't use the site for the next 14 hours.

  • Anonymous
    September 29, 2014
    Hi @Vipul, if you are referring to the site ME-20153, im deleting the items, please don't use it for the next 14 hours