Today few new learnings.
Today few new learnings.
In this article I’ll explain what care should be taken while deleting the items and restoring the items back from the recycle bin, when workflow is associated with the respective list of which items are deleted or restored
Background / Scenario : In our project we have lists to which SharePoint 2010 platform workflow is associated. We have our sandbox solution web part in which we are showing workflow tasks assigned to current user.
Note: Here we don't have option except sand box solution custom web part since we have multiple lists in different different sub sites and respective approval workflows are associated with respective lists so the respective tasks lists.
Also we couldn't use Search since we don't want to be depend on crawling. We tried with CQWP but it was showing throttling exception since in our tasks lists having lots of task items and we need to keep those for auditing purpose so we cant delete them. CQWP showing following exception as :
Figure 1 : CQWP exception for current users tasks
Case 1 : One of the user by mistake deleted the few items from the list, on which workflow already triggered, since those are approval workflows, approval task has already been assigned to the respective approvers. So those tasks are visible in there My Task listings webpart.
But as one of the user has already deleted the list items, approvers couldn't open the task items, it shows error
“You cannot complete this workflow task because the item that the workflow is running on has been deleted. If the item is in your Recycle Bin, restore it, and then try again. ”
Figure 2 : Error while opening workflow task item whose related item (item on which workflow was running) is deleted
Lesson Learned : By default If we delete any item from the list, there respective workflow tasks items are not get deleted. Those remains as it is and assigned to respective user. Also couldn't find the way to automate this. So need to delete manually.
Case 2: We have restored the deleted list items from the Recycle Bin. As soon as the items are restored in the list respective workflow triggered on these items. Our workflow was approval workflow and sending the mail. So workflow assigned the tasks to respective approvers and sent the mail. Which caused lots of confusion since workflow was already executed when item was created. Later item deleted.
User restored the items and workflow triggered again.
Lesson Learned : Initially we were not realized that workflow will trigger again when items was restored from the recycle bin. So we understood this, need to be very careful while restoring the items if workflow is associated to the list.
One possible solution to this problem is remove the workflow association and then restore the items and then again associate the workflow.
Enjoy Reading :)
As usual any comment / suggestion / feedback / questions always welcome :)