Getting 'current task' and determining its type
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2016 08:03 AM
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
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
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2016 01:37 AM
Hi John,
Regards
Martin
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2016 08:44 AM
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
Thanks
john

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 03:27 AM
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,
Best regards,
