Activiti - 如何在 Java 中设置独占网关的条件

Activiti - how to set condition for exclusive gateway in Java

我在Activiti中有一个独占网关,如何在Java代码中为独占网关设置条件变量?

variableData.put("condition", conditionVar);
taskService.complete(task.getId(), variableData);

如何提取网关流中的任务变量?有可能还是我必须使用过程变量?

进程部署时间:

  • 你可以通过扩展org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory在Java中添加表达式条件并注入到ProcessEngineConfigurationImpl

进程执行时间:

  • 您可以添加流程变量作为您定义的表达式的变量。这可能是您在 Java 中的情况造成的结果:${result == true}

    variableData.put("result", resultOfJavaCondition); taskService.complete(task.getId(), variableData);

当您使用条件独占网关设计工作流程时,它将生成如下所示的 XML,

<exclusiveGateway id="exclusiveGw" name="Exclusive Gateway" />

<sequenceFlow id="flow2" sourceRef="exclusiveGw" targetRef="theTask1">
  <conditionExpression xsi:type="tFormalExpression">${input == 1}</conditionExpression>
</sequenceFlow>

因此您需要提供 'input' 变量的值作为

variableData.put("input", 1);

如果你的任务是 ServiceTask 那么你可以像下面那样做

delegateExecution.setVariable("input",1);

需要更多帮助http://www.activiti.org/userguide/#bpmnExclusiveGateway

How I can extract task variable on gateway flow? Is it possible or I have to use process variable?

你不能。您需要从任务变量中检索值并复制到流程变量中。之后就可以用它来决定流量了

工作流中的变量存在于两个层面;流程执行级别和任务级别。如果您在任务中设置变量的值,则新值在流程级别不可用。如果要跨任务或在任务和条件流之间使用变量,则需要将变量复制到流程执行级别。流程级变量可用于任务和序列流。

https://docs.alfresco.com/5.0/concepts/wf-process-def-variables.html