英文:
how to get taskId based on processInstanceId in camunda
问题
我想确保我对Camunda工作流(WF)的理解是正确的。例如,我有一个名为foo的事务,然后foo事务将通过执行方法"ProcessInstance startProcessInstanceByKey(String processDefinitionKey)"来启动流程,并且foo事务可以获得WF的processInstanceId,然后foo事务将保存到数据库事务中。对于下一次的批准,foo事务必须调用"void complete(String taskId, Map<String, Object> variables);"来完成任务,我如何根据processInstanceId获取taskId?一个processInstanceId只有一个taskId吗?
英文:
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 ?
答案1
得分: 3
一个流程实例在启动后可能会在其执行过程中创建多个任务实例。您可以使用任务查询(根据需要应用过滤器)查询给定流程实例ID的待处理(用户)任务实例。
REST:
https://docs.camunda.org/manual/7.13/reference/rest/task/get-query/
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);
英文:
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/
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论