cancel
Showing results for 
Search instead for 
Did you mean: 

Getting 'current task' and determining its type

jlilley
Champ in-the-making
Champ in-the-making
As part of reporting/dashboarding functions in our software, I want to provide a "process instance state" report that can be accessed via REST services that we publish.  To that end, I get the "current task" for a process instance:
taskService.createTaskQuery().processInstanceBusinessKey(processInstance.getBusinessKey()).list().get(0);
Is this approach to getting the current task correct?  Let's assume for a moment lack of parallelism as our processes are fairly simple.  Can it be assumed that, while a process instance is active, there is always at least one active task that will be returned by this query?  If not, what other information should I be fetching about the process instance state that would provide a nice snapshot of what state it is in?

Also, while the Task object gives me good information, I can't see where to get the "type" of the task (e.g. UserTask, ScriptTask, ServiceTask, etc).  Is there such a getter?  If not, are there internal class names that I can compare against?

Thanks
john
3 REPLIES 3

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi John,

Can it be assumed that, while a process instance is active, there is always at least one active task that will be returned by this query?
yes

Is there such a getter?
Type of the task is stored in the model/definition.

Regards
Martin

jlilley
Champ in-the-making
Champ in-the-making
Hmmm, OK.  So how would one find the model, find the task definition, and extract the task type?  I realize that I could load the XML directly from its resource and parse it myself.  Looking for a shortcut.  Do I need to go at it from the Deployment interface?
Thanks
john

trademak
Star Contributor
Star Contributor
taskService.createTaskQuery() only returns user tasks. You would need to use runtimeService.createExecutionQuery() to get all running executions of a process instance. Every execution has an activityId property and that can be used to retrieve the Bpmn element with all the type info etc. RepositoryService.getBpmnModel gives you the BpmnModel of a process definition id and then you can use bpmnModel.getFlowElement(activityId) to get the specific Bpmn element and with that all its information.

Best regards,