Gateway default

I have this bpmn:

<startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
<userTask id="trueOrFalseDeterminer" flowable:formFieldValidation="true" flowable:assignee="userProcess" ></userTask>
<sequenceFlow id="sid-1F1A193D-3F94-4EA7-8A46-A3B1455B495F" sourceRef="startEvent1" targetRef="trueOrFalseDeterminer"></sequenceFlow>
<exclusiveGateway id="sid-5EAB2B73-562E-4B49-913C-1D9B00416EEC" default="sid-AED8CE89-7792-4890-83EE-9E2BB2606158"></exclusiveGateway>
<sequenceFlow id="sid-190928E5-3E0A-4FDD-9EBB-1D84C82F2119" sourceRef="trueOrFalseDeterminer" targetRef="sid-5EAB2B73-562E-4B49-913C-1D9B00416EEC"></sequenceFlow>
<userTask id="trueService" name="I am true" flowable:formFieldValidation="true" flowable:assignee="userDone" ></userTask>
<userTask id="falseService" name="I am false" flowable:formFieldValidation="true" flowable:assignee="userDone" ></userTask>
<endEvent id="sid-AF15BEC6-B832-4077-A0BE-EE9473CA5D9D"></endEvent>
<sequenceFlow id="sid-6DA637BF-0D86-43FC-9282-98A37D5F798D" sourceRef="trueService" targetRef="sid-AF15BEC6-B832-4077-A0BE-EE9473CA5D9D"></sequenceFlow>
<userTask id="defaultService" name="I am default" flowable:formFieldValidation="true" flowable:assignee="userDone" ></userTask>
<sequenceFlow id="sid-45B3B3C2-DCE0-456C-96D1-AC3FE2631593" sourceRef="defaultService" targetRef="sid-AF15BEC6-B832-4077-A0BE-EE9473CA5D9D"></sequenceFlow>
<sequenceFlow id="sid-D8600204-A54B-4203-B492-A97F50CC7B16" sourceRef="falseService" targetRef="sid-AF15BEC6-B832-4077-A0BE-EE9473CA5D9D"></sequenceFlow>
<sequenceFlow id="sid-AED8CE89-7792-4890-83EE-9E2BB2606158" sourceRef="sid-5EAB2B73-562E-4B49-913C-1D9B00416EEC" targetRef="defaultService"></sequenceFlow>
<sequenceFlow id="sid-69792502-7E11-44FF-911F-6D85309FF90A" name="false" sourceRef="sid-5EAB2B73-562E-4B49-913C-1D9B00416EEC" targetRef="falseService">
  <conditionExpression xsi:type="tFormalExpression"><![CDATA[${input == false}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-0638DC29-67AC-4EB5-9C0E-BAD730F87FDE" name="true" sourceRef="sid-5EAB2B73-562E-4B49-913C-1D9B00416EEC" targetRef="trueService">
  <conditionExpression xsi:type="tFormalExpression"><![CDATA[${input == true}]]></conditionExpression>
</sequenceFlow>

I suppose that if I set the input to “nothing” it should go to default service task. I mean this test should be passed but it does not pass and it goes to false user task and it shows “I am false”:

 runtimeService.startProcessInstanceByKey("userTaskAndExclusive");
    List<Task> list1 = taskService.createTaskQuery().taskAssignee("userProcess").list();
    Map<String, Object> variables = new HashMap<>();
    variables.put("input", "nothing");
    taskService.complete(list1.get(0).getId(), variables);

    List<Task> list2 = taskService.createTaskQuery().taskAssignee("userDone").list();

    assertEquals(list2.get(0).getName(), "I am default");

why does it happen?

I’m not certain why a non-boolean evaluate as == to false, but the solution is to use the variable expression functions: ${vars:eq(input, true)} and ${vars:eq(input, false)}

These compare in a null safe way.

thank you for your response. the xml was generated by flowable standard modeler. also it works correctly for false and true inputs. but when it comes to default it does not give correct result.

Your issue is that using == on a non-boolean value is evaluating as equal to false. I’m not sure why it does that, but using the variable expression functions will work for your default case. When input is the string “nothing” both ${vars:eq(input, true)} and ${vars:eq(input, false)} will evaluate to false, leaving on\ly the default path available for execution.

1 Like