none
Clean-up job to remove orphaned workflows?

    Question

  • 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.

    Thanks,

    Shelly

    Thursday, December 02, 2010 2:54 PM

Answers

  • 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.

     

    • Marked as answer by Shelly-Austin Friday, December 10, 2010 10:47 PM
    Friday, December 10, 2010 8:04 AM
    Moderator

All replies

  • 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:

    Error

    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.

     

    Monday, December 06, 2010 7:55 AM
    Moderator
  • 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'

     

    Thursday, December 09, 2010 10:46 PM
  • 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.

     

    • Marked as answer by Shelly-Austin Friday, December 10, 2010 10:47 PM
    Friday, December 10, 2010 8:04 AM
    Moderator
  • 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).
    Friday, December 10, 2010 10:59 PM
  • Hi,

    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?


    ECSpand Services for your SharePoint - Find out more at www.ecspand.com
    Wednesday, January 19, 2011 11:41 AM
  • UPDATE dbo.AllUserData
    SET tp_WorkflowVersion='1'
    WHERE tp_WorkflowVersion != '1'
    AND tp_DirName = 'quality/Lists/Document Review Tasks'
    IT Worker
    Thursday, September 22, 2011 6:59 AM