views:

118

answers:

1

Hi

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 ?

+2  A: 

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.

OedipusPrime
Ahh... I see, there isn't any workflows related to the list item I'm working on. The problem is that I'm going the other way around, that is I have a task item created by a workflow and want to check if that workflow is still running to see if it's OK to delete the task :)
armannvg