Comunda workflow process

i want to make sure my perception of camunda workflow (WF) is right. for example i have foo transaction, then the foo transaction will hit start process by executing
method “ProcessInstance startProcessInstanceByKey(String processDefinitionKey)” and in return foo transaction can get processInstanceId of WF,
then the foo transaction will be saved to DB transaction.
For next approval, the foo transaction must hit “void complete(String taskId, Map<String, Object> variables);” to complete task, how can i get taskId based on processInstanceId ?
. Does one processInstanceId only has one taskId ? is my understanding right ? (get processInstanceId → get taskId based on processInstanceId → complete task based on taskId)

Hi @wahyu.ehs,

  • When you start a process instance for any deployed process definition, one unique processInstanceId will be assigned.
  • A process may have one or more activities.
  • Each activity will have it’s one unique id called taskid.
  • A process instance can have number of taskIds which is directly proportional to the number of activities in the process.
Task task = taskService.createTaskQuery()
                   .processDefinitionKey(processDefinitionKey)  
                   .processInstanceBusinessKey(processInstanceBusinessKey)
                   .processInstanceId(processInstanceId).singleResult();
 
task.getId(); // --> Engine generated unique taskId

List<Task> taskList = taskService.createTaskQuery()
                    .processDefinitionKey(processDefinitionKey)
                    .processInstanceBusinessKey(processInstanceBusinessKey)
                   .processInstanceId(processInstanceId).list();

1 Like