cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger Complete Task when variable is set from another task

irenailievska1
Champ in-the-making
Champ in-the-making
Hi,
I am trying to create a task that will be as a sort of assistance. But I don't want to allow the users that got the task to end it. It should end when a specific variable is set to true (ex. execution.setVariable('proc_finished','true') ). But I have no idea how to do this. I can't trigger the complete event of the task. I saw somewhere about signal and boundary events but I could not find any code as to how to implement them.
I am working with JavaScript inside of the bpmn file. If someone can point me in the right direction that would be perfect.

Thank you,
Irena
1 REPLY 1

anilmann
Confirmed Champ
Confirmed Champ
May be below program answers your question.
<code>
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
<process id="process" isExecutable="true">
  <startEvent id="startProcess" name="Start Process"/>
  <scriptTask id="intializeVariables" name="Initialize Variables" scriptFormat="groovy" activiti:autoStoreVariables="false">
   <script>
    <![CDATA[System.out.println("Process Started")
    execution.setVariable("stop_process",false)
    execution.setVariable("counter",0)]]>
   </script>
  </scriptTask>
  <parallelGateway id="sid-7BF611E5-ACBA-4706-95C8-462D4CF7CC42"/>
  <scriptTask id="poll10TimesAndUpdateVariable" name="Poll 10 Times And Update Variable" scriptFormat="groovy" activiti:autoStoreVariables="false">
   <script>
    <![CDATA[System.out.println("Inside Variable Changer");
    if(execution.getVariable("counter") >=10)
    {
     execution.setVariable("stop_process",true);
    }
    else
    {
     execution.setVariable("counter",execution.getVariable("counter")+1);
     System.out.println("Variable Changed inside Variable Changer :: " + execution.getVariable("counter"));
    }]]>
   </script>
  </scriptTask>
  <scriptTask id="pollTillVariableGetsUpdate" name="Poll Till Variable Gets Updated" scriptFormat="groovy" activiti:autoStoreVariables="false">
   <script>
    <![CDATA[System.out.println("Wating for Variable to Change");]]>
   </script>
  </scriptTask>
  <sequenceFlow id="sid-E59A38DC-88E4-4ED3-8A0D-BC31246F0AF3" sourceRef="sid-7BF611E5-ACBA-4706-95C8-462D4CF7CC42" targetRef="pollTillVariableGetsUpdate"/>
  <parallelGateway id="sid-2F6F611E-EC16-47B2-BD55-1EBD084BFE1E"/>
  <exclusiveGateway id="sid-CE291149-6D27-4E82-93A1-E608C888B0ED" default="sid-A1564F56-74A8-49CA-B347-7CE2FB273F50"/>
  <exclusiveGateway id="sid-D27FFB6A-965C-4CB7-AE5B-8AF3741EADAE" default="sid-B09C244F-8B0B-4C9A-B9AD-A1C5989E2985"/>
  <sequenceFlow id="sid-1563A1F2-0F8D-4103-9128-5B224750D182" sourceRef="poll10TimesAndUpdateVariable" targetRef="sid-CE291149-6D27-4E82-93A1-E608C888B0ED"/>
  <sequenceFlow id="sid-5CA814F6-4DE0-44F5-BAAC-75B5F2E4B4CB" sourceRef="pollTillVariableGetsUpdate" targetRef="sid-D27FFB6A-965C-4CB7-AE5B-8AF3741EADAE"/>
  <scriptTask id="printCompleted" name="Print Process Completed" scriptFormat="groovy" activiti:autoStoreVariables="false">
   <script>
    <![CDATA[System.out.println("Process Completed!!!");]]>
   </script>
  </scriptTask>
  <endEvent id="sid-AF2A3EE8-06AF-4814-859D-A89442A04526">
   <terminateEventDefinition/>
  </endEvent>
  <sequenceFlow id="sid-4772B4B9-F205-4C98-AF0D-16031EC2934A" sourceRef="printCompleted" targetRef="sid-AF2A3EE8-06AF-4814-859D-A89442A04526"/>
  <intermediateCatchEvent id="sid-1CAF3871-27EE-4654-9053-D2323D971671">
   <timerEventDefinition>
    <timeDuration>PT5S</timeDuration>
   </timerEventDefinition>
  </intermediateCatchEvent>
  <sequenceFlow id="sid-E3B2C913-C5B1-46F6-8485-4120D4D1F132" sourceRef="sid-2F6F611E-EC16-47B2-BD55-1EBD084BFE1E" targetRef="printCompleted"/>
  <intermediateCatchEvent id="sid-DB398737-52A4-4C8F-9B3F-4599D7632180">
   <timerEventDefinition>
    <timeDuration>PT5S</timeDuration>
   </timerEventDefinition>
  </intermediateCatchEvent>
  <sequenceFlow id="continueToPoll2" name="Continue To Poll 2" sourceRef="sid-1CAF3871-27EE-4654-9053-D2323D971671" targetRef="pollTillVariableGetsUpdate"/>
  <sequenceFlow id="sid-401FC306-530D-4314-825F-C68BEB0D87C8" sourceRef="startProcess" targetRef="intializeVariables"/>
  <sequenceFlow id="sid-5232964E-72E3-4371-9FC3-8FFDF820637F" sourceRef="intializeVariables" targetRef="sid-7BF611E5-ACBA-4706-95C8-462D4CF7CC42"/>
  <sequenceFlow id="continueToPoll1" name="Continue To Poll 1" sourceRef="sid-DB398737-52A4-4C8F-9B3F-4599D7632180" targetRef="poll10TimesAndUpdateVariable"/>
  <sequenceFlow id="sid-5FC1F06D-5314-4647-A100-C353888C2B4B" sourceRef="sid-7BF611E5-ACBA-4706-95C8-462D4CF7CC42" targetRef="poll10TimesAndUpdateVariable"/>
  <sequenceFlow id="sid-A1564F56-74A8-49CA-B347-7CE2FB273F50" sourceRef="sid-CE291149-6D27-4E82-93A1-E608C888B0ED" targetRef="sid-DB398737-52A4-4C8F-9B3F-4599D7632180"/>
  <sequenceFlow id="sid-EEE989CB-E1F0-4D76-AE68-6105E961D4AC" sourceRef="sid-CE291149-6D27-4E82-93A1-E608C888B0ED" targetRef="sid-2F6F611E-EC16-47B2-BD55-1EBD084BFE1E">
   <conditionExpression xsi:type="tFormalExpression">
    <![CDATA[${stop_process == true}]]>
   </conditionExpression>
  </sequenceFlow>
  <sequenceFlow id="sid-B09C244F-8B0B-4C9A-B9AD-A1C5989E2985" sourceRef="sid-D27FFB6A-965C-4CB7-AE5B-8AF3741EADAE" targetRef="sid-1CAF3871-27EE-4654-9053-D2323D971671"/>
  <sequenceFlow id="sid-CFF51BD1-953B-4866-B4CA-004CBEE036B5" sourceRef="sid-D27FFB6A-965C-4CB7-AE5B-8AF3741EADAE" targetRef="sid-2F6F611E-EC16-47B2-BD55-1EBD084BFE1E">
   <conditionExpression xsi:type="tFormalExpression">
    <![CDATA[${stop_process == true}]]>
   </conditionExpression>
  </sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_process">
  <bpmndi:BPMNPlane bpmnElement="process" id="BPMNPlane_process">
   <bpmndi:BPMNShape bpmnElement="startProcess" id="BPMNShape_startProcess">
    <omgdc:Bounds height="30.0" width="30.0" x="93.5" y="309.0"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="intializeVariables" id="BPMNShape_intializeVariables">
    <omgdc:Bounds height="55.59824308181442" width="166.37672373224785" x="203.70370310411425" y="296.2008784590928"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="sid-7BF611E5-ACBA-4706-95C8-462D4CF7CC42" id="BPMNShape_sid-7BF611E5-ACBA-4706-95C8-462D4CF7CC42">
    <omgdc:Bounds height="40.0" width="40.0" x="440.0" y="304.0"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="poll10TimesAndUpdateVariable" id="BPMNShape_poll10TimesAndUpdateVariable">
    <omgdc:Bounds height="49.0" width="290.0" x="560.0" y="215.0"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="pollTillVariableGetsUpdate" id="BPMNShape_pollTillVariableGetsUpdate">
    <omgdc:Bounds height="40.0" width="287.0" x="560.0" y="440.0"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="sid-2F6F611E-EC16-47B2-BD55-1EBD084BFE1E" id="BPMNShape_sid-2F6F611E-EC16-47B2-BD55-1EBD084BFE1E">
    <omgdc:Bounds height="40.0" width="40.0" x="936.5" y="338.0"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="sid-CE291149-6D27-4E82-93A1-E608C888B0ED" id="BPMNShape_sid-CE291149-6D27-4E82-93A1-E608C888B0ED">
    <omgdc:Bounds height="40.0" width="40.0" x="936.5" y="219.5"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="sid-D27FFB6A-965C-4CB7-AE5B-8AF3741EADAE" id="BPMNShape_sid-D27FFB6A-965C-4CB7-AE5B-8AF3741EADAE">
    <omgdc:Bounds height="40.0" width="40.0" x="936.5" y="440.0"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="printCompleted" id="BPMNShape_printCompleted">
    <omgdc:Bounds height="58.07387446828517" width="205.89986568404152" x="1052.5925893766128" y="328.9630627658574"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="sid-AF2A3EE8-06AF-4814-859D-A89442A04526" id="BPMNShape_sid-AF2A3EE8-06AF-4814-859D-A89442A04526">
    <omgdc:Bounds height="28.0" width="28.0" x="1365.0" y="344.0"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="sid-1CAF3871-27EE-4654-9053-D2323D971671" id="BPMNShape_sid-1CAF3871-27EE-4654-9053-D2323D971671">
    <omgdc:Bounds height="31.0" width="31.0" x="941.0" y="573.882714726652"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNShape bpmnElement="sid-DB398737-52A4-4C8F-9B3F-4599D7632180" id="BPMNShape_sid-DB398737-52A4-4C8F-9B3F-4599D7632180">
    <omgdc:Bounds height="31.0" width="31.0" x="941.0" y="74.07407385604154"/>
   </bpmndi:BPMNShape>
   <bpmndi:BPMNEdge bpmnElement="sid-5232964E-72E3-4371-9FC3-8FFDF820637F" id="BPMNEdge_sid-5232964E-72E3-4371-9FC3-8FFDF820637F">
    <omgdi:waypoint x="370.0804268363621" y="324.0"/>
    <omgdi:waypoint x="440.0" y="324.0"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-5FC1F06D-5314-4647-A100-C353888C2B4B" id="BPMNEdge_sid-5FC1F06D-5314-4647-A100-C353888C2B4B">
    <omgdi:waypoint x="456.97701236909745" y="307.02298763090255"/>
    <omgdi:waypoint x="456.97701236909745" y="245.06665203392544"/>
    <omgdi:waypoint x="560.0" y="245.06665203392544"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-5CA814F6-4DE0-44F5-BAAC-75B5F2E4B4CB" id="BPMNEdge_sid-5CA814F6-4DE0-44F5-BAAC-75B5F2E4B4CB">
    <omgdi:waypoint x="847.0" y="460.0"/>
    <omgdi:waypoint x="936.5" y="460.0"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-E59A38DC-88E4-4ED3-8A0D-BC31246F0AF3" id="BPMNEdge_sid-E59A38DC-88E4-4ED3-8A0D-BC31246F0AF3">
    <omgdi:waypoint x="460.5" y="343.5"/>
    <omgdi:waypoint x="460.5" y="460.0"/>
    <omgdi:waypoint x="560.0" y="460.0"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-A1564F56-74A8-49CA-B347-7CE2FB273F50" id="BPMNEdge_sid-A1564F56-74A8-49CA-B347-7CE2FB273F50">
    <omgdi:waypoint x="956.933300395354" y="219.9333003953539"/>
    <omgdi:waypoint x="956.5515200895679" y="105.0739882325912"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-401FC306-530D-4314-825F-C68BEB0D87C8" id="BPMNEdge_sid-401FC306-530D-4314-825F-C68BEB0D87C8">
    <omgdi:waypoint x="123.5" y="324.0"/>
    <omgdi:waypoint x="203.70370310411425" y="324.0"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="continueToPoll1" id="BPMNEdge_continueToPoll1">
    <omgdi:waypoint x="941.0" y="90.07407385604154"/>
    <omgdi:waypoint x="705.0" y="90.07407385604154"/>
    <omgdi:waypoint x="705.0" y="215.0"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="continueToPoll2" id="BPMNEdge_continueToPoll2">
    <omgdi:waypoint x="941.0" y="589.882714726652"/>
    <omgdi:waypoint x="707.2066561895716" y="589.882714726652"/>
    <omgdi:waypoint x="707.2066561895716" y="480.0"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-EEE989CB-E1F0-4D76-AE68-6105E961D4AC" id="BPMNEdge_sid-EEE989CB-E1F0-4D76-AE68-6105E961D4AC">
    <omgdi:waypoint x="956.9191489361702" y="259.0808510638298"/>
    <omgdi:waypoint x="956.584388185654" y="338.084388185654"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-4772B4B9-F205-4C98-AF0D-16031EC2934A" id="BPMNEdge_sid-4772B4B9-F205-4C98-AF0D-16031EC2934A">
    <omgdi:waypoint x="1258.4924550606543" y="358.0"/>
    <omgdi:waypoint x="1365.0" y="358.0"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-CFF51BD1-953B-4866-B4CA-004CBEE036B5" id="BPMNEdge_sid-CFF51BD1-953B-4866-B4CA-004CBEE036B5">
    <omgdi:waypoint x="956.9019607843137" y="440.4019607843137"/>
    <omgdi:waypoint x="956.5970873786408" y="377.90291262135923"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-E3B2C913-C5B1-46F6-8485-4120D4D1F132" id="BPMNEdge_sid-E3B2C913-C5B1-46F6-8485-4120D4D1F132">
    <omgdi:waypoint x="976.0479694961141" y="358.45203050388585"/>
    <omgdi:waypoint x="1052.5925893766128" y="358.25926419109516"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-1563A1F2-0F8D-4103-9128-5B224750D182" id="BPMNEdge_sid-1563A1F2-0F8D-4103-9128-5B224750D182">
    <omgdi:waypoint x="850.0" y="239.7876984126984"/>
    <omgdi:waypoint x="936.9602385685885" y="239.96023856858847"/>
   </bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge bpmnElement="sid-B09C244F-8B0B-4C9A-B9AD-A1C5989E2985" id="BPMNEdge_sid-B09C244F-8B0B-4C9A-B9AD-A1C5989E2985">
    <omgdi:waypoint x="956.926002499478" y="479.573997500522"/>
    <omgdi:waypoint x="956.5601317383517" y="573.8828313666379"/>
   </bpmndi:BPMNEdge>
  </bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
</code>