Conditional Sequence Flow Execution

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2014 07:32 AM
I have a simple use case where i want to control the workflow execution based on conditions :
Steps in workflow:
1: Get Variable Value From External System – ServiceTask1
2: Set Variable value in x–scriptTask
3: if x > 10 then Perform A –ServiceTask2
4: if x < 10 then Perform B –ServiceTask3
5: if x > 10 then Perform C –ServiceTask4
6: Perform D
The bpmn xml that i have created is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef" typeLanguage="http://www.w3.org/2001/XMLSchema" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns
mgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns
mgdi="http://www.omg.org/spec/DD/20100524/DI">
<process isExecutable="true" id="XXXX">
<startEvent id="sid-f64d6326-749a-4dc4-b9aa-a55b3feb11f0"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask1" activiti:exclusive="false" name="Get Variable Value From External System" id="sid-394ac216-0545-44ca-9775-3f133289eae5"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask2" activiti:exclusive="false" name="if x > 10 then Perform A" id="sid-c5c0b539-7c36-4657-a27f-c7d4ee3b0319"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask3" activiti:exclusive="false" name="if x < 10 then Perform B" id="sid-94ae8d75-83f8-4c21-aa8e-973ab2446072"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask4" activiti:exclusive="false" name="if x > 10 then Perform C" id="sid-1f4bdbfe-8201-4ab6-9723-0ab81b2a6379"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask5" activiti:exclusive="false" name="Perform D" id="sid-ecb88b80-87e8-4eda-b4c8-ba49564b7d05"/>
<scriptTask activiti:async="true" completionQuantity="1" isForCompensation="false" name="Set Variable value" scriptFormat="Groovy" id="sid-6f9c0cc4-0a37-4b6e-9e26-9236365676df" startQuantity="1">
<script>execution.setVariable("x",11);</script>
</scriptTask>
<sequenceFlow id="sid-c2868a98-77ef-4461-97c1-49216a3a16eb" sourceRef="sid-f64d6326-749a-4dc4-b9aa-a55b3feb11f0" targetRef="sid-394ac216-0545-44ca-9775-3f133289eae5"/>
<sequenceFlow id="sid-d5741e2a-61de-48d5-8a7b-396d93e33ba0" sourceRef="sid-394ac216-0545-44ca-9775-3f133289eae5" targetRef="sid-6f9c0cc4-0a37-4b6e-9e26-9236365676df"/>
<sequenceFlow id="sid-b94eeea0-cd43-4605-ae4d-d3f0df0cb4d4" sourceRef="sid-6f9c0cc4-0a37-4b6e-9e26-9236365676df" targetRef="sid-c5c0b539-7c36-4657-a27f-c7d4ee3b0319">
<conditionExpression id="sid-9af778ea-7803-4820-94d3-a1ea018914ea" xsi:type="tFormalExpression">${x > 10}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-57fce966-fbf0-45d2-bf1f-82608f345fd3" sourceRef="sid-c5c0b539-7c36-4657-a27f-c7d4ee3b0319" targetRef="sid-94ae8d75-83f8-4c21-aa8e-973ab2446072">
<conditionExpression id="sid-526b0457-4b82-4b6e-a19b-32b95ca67172" xsi:type="tFormalExpression">${x < 10}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-d91e2c00-a2cf-4578-8c52-278eebf17efb" sourceRef="sid-94ae8d75-83f8-4c21-aa8e-973ab2446072" targetRef="sid-1f4bdbfe-8201-4ab6-9723-0ab81b2a6379">
<conditionExpression id="sid-274eac62-121d-474e-957c-22ff8991467d" xsi:type="tFormalExpression">${x > 10}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-31b9b6b7-f048-4921-9b26-e4cf1626f81c" sourceRef="sid-1f4bdbfe-8201-4ab6-9723-0ab81b2a6379" targetRef="sid-ecb88b80-87e8-4eda-b4c8-ba49564b7d05"/>
<sequenceFlow id="sid-35ce3733-3432-4307-93d7-0c1696b8ea39" sourceRef="sid-ecb88b80-87e8-4eda-b4c8-ba49564b7d05" targetRef="sid-05c489c5-e63e-4ca2-9b24-e1a4261eea0c"/>
<endEvent id="sid-05c489c5-e63e-4ca2-9b24-e1a4261eea0c"/>
</process>
</definitions>
Now based on the bpmn I have created the workflow will be executed in 2 ways:
1: If in scriptTask we set the value of X > 10 then only step 1, 2, 3,5,6 will get executed
2: If in scriptTask we set the value of X < 10 then only step 1, 2, 4,6 will get executed
Please confirm if this understanding is correct or will the activiti engine behave in a different way.
Steps in workflow:
1: Get Variable Value From External System – ServiceTask1
2: Set Variable value in x–scriptTask
3: if x > 10 then Perform A –ServiceTask2
4: if x < 10 then Perform B –ServiceTask3
5: if x > 10 then Perform C –ServiceTask4
6: Perform D
The bpmn xml that i have created is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef" typeLanguage="http://www.w3.org/2001/XMLSchema" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns


<process isExecutable="true" id="XXXX">
<startEvent id="sid-f64d6326-749a-4dc4-b9aa-a55b3feb11f0"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask1" activiti:exclusive="false" name="Get Variable Value From External System" id="sid-394ac216-0545-44ca-9775-3f133289eae5"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask2" activiti:exclusive="false" name="if x > 10 then Perform A" id="sid-c5c0b539-7c36-4657-a27f-c7d4ee3b0319"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask3" activiti:exclusive="false" name="if x < 10 then Perform B" id="sid-94ae8d75-83f8-4c21-aa8e-973ab2446072"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask4" activiti:exclusive="false" name="if x > 10 then Perform C" id="sid-1f4bdbfe-8201-4ab6-9723-0ab81b2a6379"/>
<serviceTask activiti:async="true" activiti:class="ServiceTask5" activiti:exclusive="false" name="Perform D" id="sid-ecb88b80-87e8-4eda-b4c8-ba49564b7d05"/>
<scriptTask activiti:async="true" completionQuantity="1" isForCompensation="false" name="Set Variable value" scriptFormat="Groovy" id="sid-6f9c0cc4-0a37-4b6e-9e26-9236365676df" startQuantity="1">
<script>execution.setVariable("x",11);</script>
</scriptTask>
<sequenceFlow id="sid-c2868a98-77ef-4461-97c1-49216a3a16eb" sourceRef="sid-f64d6326-749a-4dc4-b9aa-a55b3feb11f0" targetRef="sid-394ac216-0545-44ca-9775-3f133289eae5"/>
<sequenceFlow id="sid-d5741e2a-61de-48d5-8a7b-396d93e33ba0" sourceRef="sid-394ac216-0545-44ca-9775-3f133289eae5" targetRef="sid-6f9c0cc4-0a37-4b6e-9e26-9236365676df"/>
<sequenceFlow id="sid-b94eeea0-cd43-4605-ae4d-d3f0df0cb4d4" sourceRef="sid-6f9c0cc4-0a37-4b6e-9e26-9236365676df" targetRef="sid-c5c0b539-7c36-4657-a27f-c7d4ee3b0319">
<conditionExpression id="sid-9af778ea-7803-4820-94d3-a1ea018914ea" xsi:type="tFormalExpression">${x > 10}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-57fce966-fbf0-45d2-bf1f-82608f345fd3" sourceRef="sid-c5c0b539-7c36-4657-a27f-c7d4ee3b0319" targetRef="sid-94ae8d75-83f8-4c21-aa8e-973ab2446072">
<conditionExpression id="sid-526b0457-4b82-4b6e-a19b-32b95ca67172" xsi:type="tFormalExpression">${x < 10}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-d91e2c00-a2cf-4578-8c52-278eebf17efb" sourceRef="sid-94ae8d75-83f8-4c21-aa8e-973ab2446072" targetRef="sid-1f4bdbfe-8201-4ab6-9723-0ab81b2a6379">
<conditionExpression id="sid-274eac62-121d-474e-957c-22ff8991467d" xsi:type="tFormalExpression">${x > 10}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-31b9b6b7-f048-4921-9b26-e4cf1626f81c" sourceRef="sid-1f4bdbfe-8201-4ab6-9723-0ab81b2a6379" targetRef="sid-ecb88b80-87e8-4eda-b4c8-ba49564b7d05"/>
<sequenceFlow id="sid-35ce3733-3432-4307-93d7-0c1696b8ea39" sourceRef="sid-ecb88b80-87e8-4eda-b4c8-ba49564b7d05" targetRef="sid-05c489c5-e63e-4ca2-9b24-e1a4261eea0c"/>
<endEvent id="sid-05c489c5-e63e-4ca2-9b24-e1a4261eea0c"/>
</process>
</definitions>
Now based on the bpmn I have created the workflow will be executed in 2 ways:
1: If in scriptTask we set the value of X > 10 then only step 1, 2, 3,5,6 will get executed
2: If in scriptTask we set the value of X < 10 then only step 1, 2, 4,6 will get executed
Please confirm if this understanding is correct or will the activiti engine behave in a different way.
Labels:
- Labels:
-
Archive
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2014 07:34 AM
As the bpmn got truncated I am attaching the bpmn xml as testbpmn.txt
testbpmn.txt.zip
2 KB
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2014 03:23 AM
Hi,
you should use Exclusive gateway. Behavior is different.
http://www.activiti.org/userguide/#bpmnExclusiveGateway
Regards
Martin
you should use Exclusive gateway. Behavior is different.
http://www.activiti.org/userguide/#bpmnExclusiveGateway
only one sequence flow is selected when using the exclusive gateway. In case multiple sequence flow have a condition that evaluates to true, the first one defined in the XML (and only that one!) is selected for continuing the process. If no sequence flow can be selected, an exception will be thrown.
Regards
Martin
