Home » Sharepoint 2010

Clean-up job to remove orphaned workflows?

Does SP 2010 have any kind of clean-up job that will remove associated workflows 'in progress' from a list or library on an item that has been deleted?  We had no way to remove these 'orphans' in MOSS 2007 without writing custom code.




5 Answers Found


Answer 1

Create a SPD list workflow associated with a document library. The workflow has two actions: Assign a to-do item and then pause for 2 days;

Manually start the workflow for a document item in the library, and the task item is created in Task list;

Delete the document item;

The task is still there and the task status is still Not Started;

Edit the task, and click the complete task button, error will occur saying that the document associated with the workflow is not there:


The workflow's parent item associated with this task is currently in the recycle bin, which prevents the task from being completed.

Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator.

Troubleshoot issues with Microsoft SharePoint Foundation.

I deleted the document from the recycle bin (in two stage), the task disappeared. And I guess the orphaned workflow is also cleared.



Answer 2

I do not believe that deleting a document will automatically delete a workflow running on it.  Of course, there is no way to 'prove' that because since the document is not there, you can't get to the status page to see if the workflow is still in progress.  But am pretty sure that unless you terminate a workflow manually or thru the 'Stop workflow' action, it still remains in progress.

My scenario is:

Form1 is submitted to FormLibrary1 Workflow 1 begins on Form1 Workflow 1 creates Item1 in List1 (associated to Form1 via unique key) Workflow 2 begins on Item1 Based on conditions, Workflow2 deletes Form1 Workflow 2 ends Workflow 1 is now an orphaned workflow because its associated Form1 has been deleted but it remains 'in progress'



Answer 3

I am not saying that delete a document library item will also delete the workflow instance associated with it. But remove the deleted document item from site collection recycle bin (the second stage one) will permanently remove the document item as well as the workflow instance associated with it.


I had proved it by querying the Workflow table in the content database:

First, you can get the workflow instance id from the URL of the workflow status page.

Then you can find the record corresponding to the workflow instance in the Workflow table in the content database.

You can see that after delete the document, delete it in the user recycle bin and delete it in the site collection recycle bin, that piece of record in Workflow table is gone.


Note that query into the content database in SharePoint production environment is not supported, please do it in testing environment.



Answer 4

Thank you GuYuming.  Since you have already tested this out, I will accept that the 'orphan workflow' will be deleted 60 days from when the document is initially deleted by the 1st workflow (30 days in user recycle bin, after which it is auto-moved to the site collection recycle bin and auto-deleted from there 30 days later).

Answer 5


the proposed answer solves the job, but is not always feasible or possible. I might have hundreds of lists and libraries in my SharePoint environment and hence I would have to attach the event receiver to each and every list- which is quite impossible to keep track of. Furthermore, items might be moved from one list to another by a custom application which might cause the same problem.

Hence, there must be a way of getting rid of these orphaned workflow instances in the sharepoint database.

Any ideas (even with custom code) on how to achive that?



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure