When an approval workflow is running on a list item (like a document) and when the document is deleted, the document (and the associated workflow) is still in the Recycle bin; if we undelete the document, it get back to its original document library but the workflow status is “rejected”; I don’t think this is a good option: the workflow status should be “canceled” like when you explicitly cancel a workflow or nothing at all, or the workflow should still be active (unless it “timeouted”); how can we change the workflow status when the document ahs been deleted & restored ? By customizing the out of the box workflow, which is now possible in Sharepoint thanks to the new Office Task activity.
To fix this we can create a copy of the existing Out of the Box approval workflow and we will customize it. I will illustrate how to achieve it, it is very pretty easy.
- Start Sharepoint Designer 2010 and open your web site .
- Select the Workflows panel :
- Right click on the “Approval Sharepoint 2010” workflow and select “Copy and Modify”:
- In the next window, name your new workflow : “Approval Modified”
- The wokflow editor will show up :
- In the workflow editor, click on “start Approval…”
- In the following window, select the option “Change the behavior of the overall task process” :
- Scroll down in the workflow editor and move to the Step “When the item is Deleted”:
- Select the End task process instruction and remove it.
- Add the instruction ( as illustrated in the next picture)
Set workflow status to Cancelled
Stop the workflow and set the log message to “workflow cancelled because the item has been deleted”.
- Click on the Save button in the ribbon and on the Publish button :
- Associate your new workflow template with a new list
- Start a workflow instance on a document :
- Delete the document :
- Go to the Recycle Bin and restore the document:
- Go back to the document library : you will notice that the workflow status is now“Canceled” and not “Rejected” anymore
If you click on the workflow status (here “Canceled” ), you will be redirected to the workflow history and your custom message will show-up :