0
votes

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 the task, how can i get taskId based on processInstanceId ? . Does one processInstanceId only has one taskId ?

2

2 Answers

2
votes

A process instance could potentially create multiple task instances after it has been started, as part of its execution. You can query the pending (user) task instance(s) for a given process instance id using a TaskQuery (apply filters as required).

REST: https://docs.camunda.org/manual/7.13/reference/rest/task/get-query/

JAVA: https://docs.camunda.org/javadoc/camunda-bpm-platform/7.14/org/camunda/bpm/engine/TaskService.html#createTaskQuery--

RuntimeService runtimeService = engine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MyProcess");

TaskService taskService = engine.getTaskService();
List<Task> taskList = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();

Task task = taskList.get(0);
Map<String, Object> inputData = new HashMap<String, Object>();
inputData.put("myInput", true);
taskService().complete(task.getId(), inputData);
-1
votes

Something like that processEngine .getManagementService() .createJobQuery() .executionId(executionId) .singleResult() .getId()