2

We have workflow associated to a list. The workflow is complicated and has many tasks on it.

I noticed that the Workflow tasks still exists even if you delete the associated item. or when you cancel the workflow.

I would like to know if this is a common problem and how can I fix>?

Options 1. Create a site collection workflow that runs everyday and basically looking orphan tasks. On the same loop check that if the associated workflow is cancelled.

5
  • 2
    Questions about 3rd party tools are off topic here. For Nintex related questions you should visit their support forums connect.nintex.com/forums. – Eric Alexander Jan 16 '14 at 16:51
  • that is incorrect, I have seen many Nintex questions and there is a tag called Nintex. – Luis Valencia Jan 17 '14 at 9:44
  • 2
    "Questions on problems encountered using commercial 3rd-party software or plugins are off-topic as they can be more easily answered by the specific vendor's support team." – Eric Alexander Jan 17 '14 at 16:26
  • 2
    Those hve all been closed, 3rd party products used to be ok to post, but since the migration to the stackexchange network they have been deemed off topic. If you can rephrase this so it isn't about Nintex specifically, flag the question and we will reopen it. – Eric Alexander Jan 17 '14 at 17:01
  • 1
    I removed the nintex thing. it doesnt matter if its nintex or non, as the problem its with the workflow tasks and not the nintex workflow itself – Luis Valencia Jan 18 '14 at 17:57
2

Another option is to code the cleaning logic in a timer job.

Create a timer job that runs daily/weekly/monthly (night hours), loop through the tasks list and delete orphan tasks and tasks of canceled workflows.

1.) Delete orphan tasks

Tasks created by workflows started on list items have field ‘WorkflowListId’ that contains the Guid of the list and field ‘WorkflowItemId’ that contains the ID of the associated list item.

Tasks created otherwise (not by list workflows) have null in ‘WorkflowListId’ and ‘WorkflowItemId’.

You can use these two fields to get only the workflow tasks and if there is no item with that ID in the list (the item has been deleted) then delete the task.

2.) Delete tasks of terminated workflows

You can get the workflow status and if it is stoped by the user then delete the task.

int id = Convert.ToInt32(taskItem[SPBuiltInFieldId.WorkflowItemId]);
SPListItem item = list.GetItemById(id);

string workflowInstanceId = taskItem[SPBuiltInFieldId.WorkflowInstanceID].ToString();
SPWorkflow workflow = item.Workflows[new Guid(workflowInstanceId)];
If (workflow.StatusValue = SPWorkflowStatus.StoppedByUser)
{
    taskItem.Delete();
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.