How to use conditionals?

Hello folks!

I’ve implemented the bpmn on my application and here is the diagram that i create:

And the XML generated is the following:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://activiti.org/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">

<bpmn:process id="test-weather" isExecutable="false">
  <bpmn:startEvent id="StartEvent_1" name="Start">
    <bpmn:outgoing>SequenceFlow_1gsxx9t</bpmn:outgoing>
  </bpmn:startEvent>
  <bpmn:serviceTask id="ServiceTask_07hoa80" name="Get Weather from Rio de Janeiro" camunda:class="net.mycompany.tasks.HttpRequestTask">
    <bpmn:extensionElements>
      <camunda:field name="ouputKey">
        <camunda:string>test</camunda:string>
      </camunda:field>
      <camunda:field name="url">
        <camunda:string>https://jsonplaceholder.typicode.com/posts/1</camunda:string>
      </camunda:field>
      <camunda:field name="method">
        <camunda:string>GET</camunda:string>
      </camunda:field>
    </bpmn:extensionElements>
    <bpmn:incoming>SequenceFlow_00y8mb1</bpmn:incoming>
    <bpmn:outgoing>SequenceFlow_0r0ptxv</bpmn:outgoing>
  </bpmn:serviceTask>
  <bpmn:endEvent id="EndEvent_1l83ua0" name="End">
    <bpmn:incoming>SequenceFlow_0r0ptxv</bpmn:incoming>
    <bpmn:incoming>SequenceFlow_1706os7</bpmn:incoming>
  </bpmn:endEvent>
  <bpmn:sequenceFlow id="SequenceFlow_0r0ptxv" sourceRef="ServiceTask_07hoa80" targetRef="EndEvent_1l83ua0" />
  <bpmn:exclusiveGateway id="ExclusiveGateway_0zvqalw" name="Check City">
    <bpmn:incoming>SequenceFlow_1gsxx9t</bpmn:incoming>
    <bpmn:outgoing>SequenceFlow_00y8mb1</bpmn:outgoing>
    <bpmn:outgoing>SequenceFlow_06mr7ht</bpmn:outgoing>
  </bpmn:exclusiveGateway>
  <bpmn:sequenceFlow id="SequenceFlow_1706os7" sourceRef="ServiceTask_025p49k" targetRef="EndEvent_1l83ua0" />
  <bpmn:sequenceFlow id="SequenceFlow_1gsxx9t" sourceRef="StartEvent_1" targetRef="ExclusiveGateway_0zvqalw" />
  <bpmn:sequenceFlow id="SequenceFlow_00y8mb1" sourceRef="ExclusiveGateway_0zvqalw" targetRef="ServiceTask_07hoa80">
    <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">
      <![CDATA[${city == '123'}]]>
    </bpmn:conditionExpression>
  </bpmn:sequenceFlow>
  <bpmn:sequenceFlow id="SequenceFlow_06mr7ht" sourceRef="ExclusiveGateway_0zvqalw" targetRef="ServiceTask_025p49k">
    <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">
      <![CDATA[${city == '312'}]]>
    </bpmn:conditionExpression>
  </bpmn:sequenceFlow>
  <bpmn:serviceTask id="ServiceTask_025p49k" name="Get Weather from Sao Paulo" camunda:class="net.mycompany.tasks.HttpRequestTask">
    <bpmn:extensionElements>
      <camunda:field name="ouputKey">
        <camunda:string>test</camunda:string>
      </camunda:field>
      <camunda:field name="url">
        <camunda:string>
          <![CDATA[https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22nome%2C%20ak%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys]]>
        </camunda:string>
      </camunda:field>
      <camunda:field name="method">
        <camunda:string>GET</camunda:string>
      </camunda:field>
    </bpmn:extensionElements>
    <bpmn:incoming>SequenceFlow_06mr7ht</bpmn:incoming>
    <bpmn:outgoing>SequenceFlow_1706os7</bpmn:outgoing>
  </bpmn:serviceTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
  <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="test-weather">
    <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
      <dc:Bounds x="96" y="204" width="36" height="36" />
      <bpmndi:BPMNLabel>
        <dc:Bounds x="69" y="240" width="90" height="20" />
      </bpmndi:BPMNLabel>
    </bpmndi:BPMNShape>
    <bpmndi:BPMNShape id="ServiceTask_07hoa80_di" bpmnElement="ServiceTask_07hoa80">
      <dc:Bounds x="372" y="80" width="100" height="80" />
    </bpmndi:BPMNShape>
    <bpmndi:BPMNShape id="EndEvent_1l83ua0_di" bpmnElement="EndEvent_1l83ua0">
      <dc:Bounds x="612" y="204" width="36" height="36" />
      <bpmndi:BPMNLabel>
        <dc:Bounds x="585" y="240" width="90" height="20" />
      </bpmndi:BPMNLabel>
    </bpmndi:BPMNShape>
    <bpmndi:BPMNEdge id="SequenceFlow_0r0ptxv_di" bpmnElement="SequenceFlow_0r0ptxv">
      <di:waypoint xsi:type="dc:Point" x="472" y="120" />
      <di:waypoint xsi:type="dc:Point" x="542" y="120" />
      <di:waypoint xsi:type="dc:Point" x="542" y="222" />
      <di:waypoint xsi:type="dc:Point" x="612" y="222" />
      <bpmndi:BPMNLabel>
        <dc:Bounds x="500" y="110" width="90" height="20" />
      </bpmndi:BPMNLabel>
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNShape id="ExclusiveGateway_0zvqalw_di" bpmnElement="ExclusiveGateway_0zvqalw" isMarkerVisible="true">
      <dc:Bounds x="250" y="197" width="50" height="50" />
      <bpmndi:BPMNLabel>
        <dc:Bounds x="230" y="247" width="90" height="20" />
      </bpmndi:BPMNLabel>
    </bpmndi:BPMNShape>
    <bpmndi:BPMNEdge id="SequenceFlow_1706os7_di" bpmnElement="SequenceFlow_1706os7">
      <di:waypoint xsi:type="dc:Point" x="472" y="333" />
      <di:waypoint xsi:type="dc:Point" x="542" y="333" />
      <di:waypoint xsi:type="dc:Point" x="542" y="222" />
      <di:waypoint xsi:type="dc:Point" x="612" y="222" />
      <bpmndi:BPMNLabel>
        <dc:Bounds x="497" y="267.5" width="90" height="20" />
      </bpmndi:BPMNLabel>
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNEdge id="SequenceFlow_1gsxx9t_di" bpmnElement="SequenceFlow_1gsxx9t">
      <di:waypoint xsi:type="dc:Point" x="132" y="222" />
      <di:waypoint xsi:type="dc:Point" x="250" y="222" />
      <bpmndi:BPMNLabel>
        <dc:Bounds x="146" y="212" width="90" height="20" />
      </bpmndi:BPMNLabel>
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNEdge id="SequenceFlow_00y8mb1_di" bpmnElement="SequenceFlow_00y8mb1">
      <di:waypoint xsi:type="dc:Point" x="275" y="197" />
      <di:waypoint xsi:type="dc:Point" x="275" y="120" />
      <di:waypoint xsi:type="dc:Point" x="372" y="120" />
      <bpmndi:BPMNLabel>
        <dc:Bounds x="230" y="148.5" width="90" height="20" />
      </bpmndi:BPMNLabel>
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNEdge id="SequenceFlow_06mr7ht_di" bpmnElement="SequenceFlow_06mr7ht">
      <di:waypoint xsi:type="dc:Point" x="275" y="247" />
      <di:waypoint xsi:type="dc:Point" x="275" y="333" />
      <di:waypoint xsi:type="dc:Point" x="372" y="333" />
      <bpmndi:BPMNLabel>
        <dc:Bounds x="230" y="280" width="90" height="20" />
      </bpmndi:BPMNLabel>
    </bpmndi:BPMNEdge>
    <bpmndi:BPMNShape id="ServiceTask_025p49k_di" bpmnElement="ServiceTask_025p49k">
      <dc:Bounds x="372" y="293" width="100" height="80" />
    </bpmndi:BPMNShape>
  </bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

The problem is when i run my flow and use the variable “city” with value “123” on call “runtime.startProcessInstanceByKey(name, vars)” the class called is “wrong”.

My custom class is called but URL should be other and it’s going to “false” condition (Get weather from Sao Paulo instead Get weather from Rio de Janeiro).

What i’m doing wrong?

You need to make the BPMN Executable.

Your XML is currently showing:

isExecutable="false">

Can you confirm that the city variable that you are outputting from your java file has the String Value?

Hi @jackhammer,

@StephenOTT, is right your process should be marked executable. Could yoo please also share exact code which you use to start the process?

Cheers,
Askar