java - Camunda : get active tasks -
how can list of active tasks in code use in camunda ?
i @ answer "how query position of process instance?" can't understand "processinstanceid" , supposed make method works.
here's code i'm trying :
package org.camunda.bpm; import java.util.hashmap; import java.util.list; import java.util.map; import org.camunda.bpm.engine.processengine; import org.camunda.bpm.engine.repositoryservice; import org.camunda.bpm.engine.runtimeservice; import org.camunda.bpm.engine.runtime.processinstance; import org.camunda.bpm.model.bpmn.bpmnmodelinstance; import org.camunda.bpm.model.xml.instance.modelelementinstance; public class allactiveactivities { public map<string, string> getallactiveactivities(string processinstanceid) { // engine services processengine processengine = bpmplatform.getdefaultprocessengine() runtimeservice runtimeservice = processengine.getruntimeservice(); repositoryservice repositoryservice = processengine.getrepositoryservice(); // process instance processinstance processinstance = runtimeservice.createprocessinstancequery() .processinstanceid(processinstanceid) .singleresult(); hashmap<string, string> activitynamebyactivityid = new hashmap<string, string>(); // active activities of process instance list<string> activeactivityids = runtimeservice.getactiveactivityids(processinstance.getid()); // bpmn model of process instance bpmnmodelinstance bpmnmodelinstance = repositoryservice.getbpmnmodelinstance(processinstance.getprocessdefinitionid()); (string activeactivityid : activeactivityids) { // speaking name of each activity in diagram modelelementinstance modelelementbyid = bpmnmodelinstance.getmodelelementbyid(activeactivityid); string activityname = modelelementbyid.getattributevalue("name"); activitynamebyactivityid.put(activeactivityid, activityname); } // map contains active activities return activitynamebyactivityid; } }
thanks in advance help.
the following statement return active tasks, can standalone tasks.
processengine.gettaskservice().createtaskquery().active().list()
if want active tasks corresponding specific running process have add .processinstanceid(processinstanceid)
statement before .list()
. processinstanceid
id
identifies process instance. if start process/workflow process instance created unique id. these id can example execute following statement.
int processinstanceid = processengine.getruntimeservice() .createprocessinstancequery() .processdefinitionkey(processdefinitionkey) .singleresult() .getid()
the variable processdefinitionkey
id set in process definition xml.
Comments
Post a Comment