Search code examples
javaactiviti

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?


Solution

  • 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