Question

I'm having a problem relating to Sharepoint workflows and the associated task list.

I have 2 custom workflows that we created for our product. They both use the same Task list that has a custom content type that inherits from the Task content type.

Now I have a case where a running workflow has been deleted via the list has been deleted or the document, this results in orphaned tasks.

I want to overwrite the Task lists OnDeleting event, so that users can cleanup their tasks so that it won't contain unneccessary orphaned tasks. So my item deleting looks like this

public override void ItemDeleting(SPItemEventProperties properties)
{
   SPListItem currentListItem = properties.ListItem;
}

The problem is that when I go into debug mode and check the currentListItem.Workflows.Count field then it's always 0. It doesn't matter which workflow I initiate or what task i look at, the SPWorkflowCollection returned is always empty :(

I was wondering if this might be related to a bug in our custom workflow where it's not wired up properly (but it finishes correctly and tasks are deleted when a workflow is terminated) or am I looking at this the wrong way ?

Was it helpful?

Solution

The currentListItem you have in scope here is the task item itself, not the list item that the workflow is running against. The task doesn't have a workflow running against it, so the zero count is expected.

If you're trying to get to the workflow tasks associated with workflows on an item you're deleting you'd need this kind of event handler on each list the workflow is activated on, not on the tasks list the workflow uses to store its tasks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top