cancel
Showing results for 
Search instead for 
Did you mean: 

Get Workflow Active Tasks in Javascript

joaotpd
Champ on-the-rise
Champ on-the-rise
Hi all!

I'm trying to do a script to get all active tasks for a workflow:

<javascript>
//…

var workflows = doc.activeWorkflows;

var nWorkflows = workflows.length;

if (nWorkflows > 0)
{
     for each ( var workflow in workflows )
     {
          var workflowId = workflow.getId();
         
          var workflowActiveTasks = workflow.WHAT_FUNCTION_HERE;

          (…)
     }

}

//…
</javascript>

Is there function to retrieve all active tasks for a workflow?

Thanks in advance,

João
2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
you need to first get workflow definition

var myworkflowid=getDefinition("workflowid");

then get all the active instances of that definition as follow

var activeinstanceslist=myworkflowid.getActiveInstances();
activeinstanceslist will be A JavaScript array containing JScriptWorkflowInstances.

joaotpd
Champ on-the-rise
Champ on-the-rise
Hi and thanks for the reply… I trying to do what you suggest:


<javascript>
//…

var workflows = doc.activeWorkflows;
var nWorkflows = workflows.length;
      
if (nWorkflows > 0)
{
     for each ( var docWorkflow in workflows )
     {
          //docWorkflow is an JscriptWorkflowInstance?
          var docWorkflowId = docWorkflow.getId();         
          var workflowDefinition = workflow.getDefinition(docWorkflowId);
          var activeInstaces = workflowDefinition.getActiveInstances();
          var nActiveInstaces = activeInstaces.length;
          logger.log("ACTIVE INSTANCES: " + nActiveInstaces);
     }
}

//…
</javascript>

But i'm getting an id error… "Workflow definition jbpm does not exist"…

I'm not getting something here… ….

Please help…

Thanks in advance!

João