2

I have a task that is associated with an item (in another list) that has a running workflow. However, the item was deleted over a year ago and therefore it is no longer recoverable from the recycle bins. Now that this has been brought to my attention, I would like to delete the task, or at least change some of its properties so it does not show up as an open task for my client.

To delete, I have tried something like the following:

001: $web = get-spweb http://{my web addr}
002: $tasklist = $web.lists.trygetlist("Tasks")
003: $task = $tasklist.getitembyid(13445)
004: $task.name
005: $task.recycle();

However this results in an error "Item does not exist. It may have been deleted by another user." although clearly it does exist as both lines 003 & 004 above execute without error.

Another option I thought was to reassign the task to myself, or change the status field to completed, like below:

006: $task["AssignedTo"] = $mySPUser
007: $task["Status"] = "Completed"
008: $task.update()

However, line 008 fails with message "The workflow's parent item associated with this task is currently in the recycle bin, which prevents the task from being completed.". However, the parent item $task[WorkflowItemId"] is no longer in the recycle bins.

So, I'm stuck unless someone can think of a way around this.

FYI... In the past when similar situations arose I would restore the parent item, terminate the workflow, then delete the parent item again. Since then, I have also implemented event receiver code to prevent users from deleting items with running workflows so this issue should not reoccur in the future. However, this particular instance occurred prior to that code being in place and I was not notified in time to perform the restore/terminate/delete sequence.

  • Have you checked the ULS Logs? There may be additional error information that could help in troubleshooting. – Tom Resing Apr 8 '14 at 21:32
  • Good suggestion. When I try $task.recycle() I see a ULS Event saying "Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWinOEItemEventReceiver ... Item does not exist. It may have been deleted by another user." – Carl Apr 9 '14 at 15:03
  • Also, I am guessing that the message "Item does not exist" must be referring to the workflow parent item (which has in fact been deleted) and not the task itself. – Carl Apr 9 '14 at 15:19
  • My next troubleshooting steps would be to first look at all of the events in the ULS occurring just before or after every call to $task.recycle() then, if that doesn't reveal the issue, get out a dissasembler and start walking through the sharepoint code to find the issue. – Tom Resing Apr 15 '14 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.