We currently have an issue with the My Tasks list in the CMS. The AJAX service it goes to returns a 404 when a page referenced by a running workflow instance no longer exists (delete page and clear recycle bin). This means the entire My Tasks list fails to work.
As a workaround, we would like to be able to get a list of all currently running workflow instances of type "Parallel Approval" in code, so that we can delete those which have invalid content references associated with them.
Is it possible to -
1. List all running workflow instances in code:
2. Delete a running workflow instance in code:
WorkflowSystem.InstanceHandler.TerminateInstance(instance.InstanceId, "Terminate instance from code");
Hope that help!
That's perfect, thanks!
If anyone has a similar problem to what I described in OP, this is the code I have in my scheduled job now to fix the problem. Hopefully someone else will find it useful -
var instances = WorkflowSystem.InstanceHandler.GetInstances(AccessLevel.NoAccess);
_numTotalInstances = instances.Count;
_numDeletedInstances = 0;
foreach (var instance in instances)
catch (ContentNotFoundException ex)
WorkflowSystem.InstanceHandler.TerminateInstance(instance.InstanceId, "Invalid page reference", AccessLevel.NoAccess);
Nice code Jallen! Thanks!