Last updated on October 10th, 2019 at 02:46 pm

Overview

A daily Workflow Auto Cleanup job runs to permanently delete workflow instances and related task entries that still exist 60 days after a workflow is completed or canceled.  Workflow history items themselves are not deleted, but the entry point to view them on the status page for a particular instance of a workflow will no longer be available.  As the workflow history and task lists grow in size, site performance may be compromised.

Personal Experience

While perusing storage metrics I noticed a workflow history list that was taking up 4 GB of space.  Upon further investigation, I found the workflow history list contained more than 8.2 MILLION items.  This prompted me to develop PowerShell scripts to 1) locate and provide information regarding our workflow history lists and 2) remove old workflow history items older than 4 months.  During discovery I found several other workflow history lists with millions of items.

Locating Workflow History Lists

The following PowerShell script will locate and display all workflow history lists.  The script provides insight regarding site title, URL, list name and item count for each discovered workflow history list.

Purge Workflow History List

The first thing to determine is how much workflow history you want to keep.  The next step is actually purging the workflow history list.  Information Management Retention Policies can be configured on the affected list(s), but they don’t work very well when there are loads of items in the list(s).  I recommend purging the list(s) with PowerShell and THEN creating the policies.

The following script will purge a workflow history list.  The list is purged in batches of 100 items at a time to minimize performance impact.

 

Information Management Retention Policies

After the workflow lists have been purged, create Information Management Retention Policies to keep them cleaned up.

  1. Open the Workflow history list (site URL/Lists/Workflow History
  2. Open the list settings page
  3. Select “Information management policy settings” in the Permissions and Management section. If you don’t see this option, you may need to enable the site collection feature “Library and Folder Based Retention”.
  4. Under Content Type Policies, select the Workflow History content type
  5. Check/Enable the “Enable Retention” check box
  6. Click “Add a retention stage”
  7. From the Stage Properties dialog under Event > Time Period change the settings to Date Occurred + 120 days   (to purge any items over 4 months old)
  8. Under Action select Permanently Delete
  9. Click OK to close the Stage Properties dialog
  10. Click OK to save the list policy.  The expired items will be deleted the next time the timer jobs run.
  11. Open Central Administration -> Monitoring -> Review Job Definitions
  12. In the list of timer jobs, select Information management policy and schedule the job.  Then, select Run Now.
  13. In the list of timer jobs, select Expiration policy and schedule the job.  Ensure previous job finishes running, then select Run Now.