Hello,
I have a called "Workflow failure monitor" in which it every 5 minutes it gets a list of Sorted Executions for a given workflow. If there's a token in a failed state it sends an email & txt. This morning I noticed there were roughly 800 tokens in a running state for the workflow "Workflow failure monitor". The workflow only takes 1 second to complete and I have no idea why the initial and subsequent tokens stayed in a running state. My thought was:
1.Get the Sorted Executions for the workflow "Workflow failure monitor"
2.Loop them looking for !=complete, !=canceled and !=failed as well as excluding the current workflow run
3.If a token was found matching the criteria from #2 above, I would cancel it.
However, when testing the cancel() method of a token I get an error of "Cannot cancel workflow". The code for the cancel routine is below. Thank you for your help!
-----------------------------------------------------------------------------------------------------------------------------------
var wfs = new Array();
wfs.push(workflow.rootWorkflow);
var tokens = System.getModule("com.vmware.web.webview").getSortedExecutionsForWorkflowList(wfs,null);
System.log(workflow.id);
// Cancel any running workflow tokens of this workflow
for(var i=0; i < tokens.length; i++)
{
if (tokens[i].state != "completed" && tokens[i].state != "canceled" && tokens[i].state != "failed")
{
if (tokens[i].id != workflow.id)
tokens[i].cancel();
}
}