HOW TO: Removing Mass Waiting Workflows

From time to time you can find yourself in a scenario where your System Jobs list is clogged up with workflows stuck in a waiting state. The Microsoft supported way of removing the items is through performing an advance find on waiting workflows and manually cancelling up to 250 workflows at a time. In extreme situations we do have another option which is suited to cases where we don’t have manageable amounts of workflows stuck in waiting.

Scenario

So our scenario is we have 50000 workflows stuck in waiting and we don’t have time to cancel them all manually.

Solution

This solution is not support by Microsoft, so make sure you backup the database before performing the following action. The following SQL statements need to be run on the MSCRM database. The statements will bulk delete the waiting workflows.

Please replace with the actual name of the workflow you are interested in deleting.

delete from workflowwaitsubscriptionbase where asyncoperationid in (select asyncoperationid from asyncoperationbase where name = '' and StateCode = 1)
delete from workflowlogbase where asyncoperationid in (select asyncoperationid from asyncoperationbase where name = '' and StateCode = 1)
delete from asyncoperationbase where name = '' and StateCode = 1

Leave a Reply

Your email address will not be published. Required fields are marked *