AI OnAI Off
Hi Jallen,
1. List all running workflow instances in code:
WorkflowSystem.InstanceHandler.GetInstances(AccessLevel.Read);
2. Delete a running workflow instance in code:
WorkflowSystem.InstanceHandler.TerminateInstance(instance.InstanceId, "Terminate instance from code");
Hope that help!
//Ha
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)
{
if (_stop)
{
return;
}
try
{
_contentRepository.Get(instance.PageLink);
}
catch (ContentNotFoundException ex)
{
_pageReferences.Add(instance.PageLink.ToString());
WorkflowSystem.InstanceHandler.TerminateInstance(instance.InstanceId, "Invalid page reference", AccessLevel.NoAccess);
_numDeletedInstances++;
}
}
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 -
Thanks.