如何基于Camunda中的processInstanceId获取taskId。

huangapple go评论95阅读模式
英文:

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/

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);
英文:

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(&quot;MyProcess&quot;);

TaskService taskService = engine.getTaskService();
List&lt;Task&gt; taskList = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();

Task task = taskList.get(0);
Map&lt;String, Object&gt; inputData = new HashMap&lt;String, Object&gt;();
inputData.put(&quot;myInput&quot;, true);
taskService().complete(task.getId(), inputData);

huangapple
  • 本文由 发表于 2020年8月6日 14:08:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63277776.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定