J-Alex
J-Alex

Reputation: 7107

Activiti - how to set condition for exclusive gateway in Java

I have an exclusive gateway in Activiti, how I can set the condition variable in Java code for exclusive gateway?

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

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

Upvotes: 5

Views: 8959

Answers (3)

alevi.dcosta
alevi.dcosta

Reputation: 353

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

You cant. You need to retrieve the value from task variable and copy into process variable. After which you can use it decide the flow.

Variables in workflows exist at two levels; the process execution level and the task level. If you set the value of a variable in a task, the new value is not available at the process level. If you want to use a variable across tasks, or between a task and conditional flow, you need to copy the variable to the process execution level. Process level variables are available to tasks and sequence flows.

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

Upvotes: 0

NIrav Modi
NIrav Modi

Reputation: 6962

When you design your workflow with conditional exclusive gateway then it will generate XML like below,

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

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

so you need to provide a value of 'input' variable as

variableData.put("input", 1);

If your task is ServiceTask then you can do like below

delegateExecution.setVariable("input",1);

For more help http://www.activiti.org/userguide/#bpmnExclusiveGateway

Upvotes: 9

fersmi
fersmi

Reputation: 621

In process deploy time:

  • you can add expression condition in Java by extends org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory and inject to ProcessEngineConfigurationImpl

In process execution time:

  • you can add process variables as variable of you defined expression. It could be result of your condition in Java: ${result == true}

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

Upvotes: 1

Related Questions