cancel
Showing results for 
Search instead for 
Did you mean: 

Intermediate catch event triggers even when all my tasks are completed

satyakamkaul
Champ in-the-making
Champ in-the-making
Hello Users,
I have a vaccation request workflow.
In the flow there are multiple activities. The requirement is when the workflow is not completed with in some time frame i am supposed to do some things. So for that purpose i have used an intermediatecatch event which is started in a parallel gateway after the start event.
Now even if i complete all the activities in the workflow before the timer it still gets triggered which is not what is expected.
I believe that the timer gets triggered because the process instance is still not completed and its waiting for timer. But should not the timer be disappeared once my activites are finished or completed.
I am not understanding that why the process is not completed even when my tasks are finised, please help me in how to achieve this.
Here is my bpmn xml.


<?xml version="1.0" encoding="UTF-8" ?>
<definitions id="definitions"
  targetNamespace="http://activiti.org/bpmn20"
  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"
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <process id="AppealRequest" name="Appeal request">
 
     
    <startEvent id="request" activiti:initiator="requesterName">
      <extensionElements>
        <activiti:formProperty id="ticketStatus" name="Ticket Status" type="string"/>
          <activiti:formProperty id="resendApplication" name="Resend Application Counter" type="long"/>
      </extensionElements>
    </startEvent>
    <intermediateCatchEvent id="timer23days" name="TimerCatchEvent">
    <extensionElements>
    <activiti:executionListener class="com.getinsured.hix.tkm.activiti.NotificationListener" event="end">
     </activiti:executionListener>
     </extensionElements>
      <timerEventDefinition>
        <timeDuration>PT40S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <!– <intermediateCatchEvent id="timer29days" name="TimerCatchEvent">
    <activiti:executionListener class="org.activiti.examples.bpmn.executionlistener.RecorderExecutionListener" event="end">
          <activiti:field name="parameter" stringValue="Start Event Listener" />
        </activiti:executionListener>
      <timerEventDefinition>
        <timeDuration>PT50S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <intermediateCatchEvent id="timer30days" name="TimerCatchEvent">
    <activiti:executionListener class="org.activiti.examples.bpmn.executionlistener.RecorderExecutionListener" event="end">
          <activiti:field name="parameter" stringValue="Start Event Listener" />
        </activiti:executionListener>
      <timerEventDefinition>
        <timeDuration>PT60S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent> –>
   
   
    <sequenceFlow id="flow1" sourceRef="request" targetRef="fork" />
    <parallelGateway id="fork" />
    <sequenceFlow id="flow2" sourceRef="request" targetRef="initiateAppealRequest" />
    <sequenceFlow id="flow23daystimer" sourceRef="request" targetRef="timer23days" />
    <!– <sequenceFlow id="flow29daystimer" sourceRef="request" targetRef="timer29days" />
    <sequenceFlow id="flow30daystimer" sourceRef="request" targetRef="timer30days" /> –>
   
     <userTask id="initiateAppealRequest" name="Initiate appeal request" >
      <documentation>
        ${requesterName} requests for appeal.
      </documentation>
      <extensionElements>
        <activiti:formProperty id="numberOfDays" name="Number of days" type="long" required="true">1</activiti:formProperty>
        <activiti:formProperty id="vacationMotivation" name="Motivation" type="string" />
      </extensionElements>
      <humanPerformer>
        <resourceAssignmentExpression>
          <formalExpression>${requesterName}</formalExpression>
        </resourceAssignmentExpression>
      </humanPerformer> 
    </userTask>
    <sequenceFlow id="flow222" sourceRef="initiateAppealRequest" targetRef="handleRequest" />
   
    <userTask id="handleRequest" name="Handle appeal request" >
      <documentation>
        ${requesterName} would like to make appeal.
      </documentation>
      <extensionElements>
        <activiti:formProperty id="ticketStatus" name="Do you approve this appeal" type="enum" required="true">
          <activiti:value id="Approve" name="Approve" />
          <activiti:value id="Reject" name="Reject" />
          <activiti:value id="NeedInfo" name="NeedInfo" />
        </activiti:formProperty>
        <activiti:formProperty id="managerMotivation" name="Motivation" type="string" />
      </extensionElements>
      <potentialOwner>
        <resourceAssignmentExpression>
        <formalExpression>${groupName}</formalExpression>
<!–           <formalExpression>Triage Queue</formalExpression> –>
        </resourceAssignmentExpression>
      </potentialOwner>        
    </userTask>
    <sequenceFlow id="flow33" sourceRef="handleRequest" targetRef="requestApprovedDecision" />
   
    <exclusiveGateway id="requestApprovedDecision" name="Appeal approved?" />
    <sequenceFlow id="flow4" sourceRef="requestApprovedDecision" targetRef="sendApprovalMail">
      <conditionExpression xsi:type="tFormalExpression">${ticketStatus == 'Approve'}</conditionExpression>
    </sequenceFlow>
   
    <task id="sendApprovalMail" name="Send confirmation e-mail" />
    <sequenceFlow id="flow5" sourceRef="sendApprovalMail" targetRef="theEnd1" />
    <endEvent id="theEnd1" />
   
    <sequenceFlow id="flow6" sourceRef="requestApprovedDecision" targetRef="generateDataset">
      <conditionExpression xsi:type="tFormalExpression">${ticketStatus == 'Reject'}</conditionExpression>
    </sequenceFlow>
   
     <scriptTask id="generateDataset" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">
          <script><![CDATA[
         
           
               var reportData = null;
              
               if(execution.getVariable("resendApplication")){
                  reportData = parseInt(execution.getVariable("resendApplication"));
                  reportData =reportData+1;
               }
              
               else{
               reportData = 1;
               }
              
               execution.setVariable("resendApplication", reportData);
              
          ]]></script>
    </scriptTask>
   
   
    <sequenceFlow id="flow7" sourceRef="generateDataset" targetRef="rejectRequestDecision" />
   
    <exclusiveGateway id="rejectRequestDecision" name="Resend request?" />
     <sequenceFlow id="flow8" sourceRef="rejectRequestDecision" targetRef="theEnd2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${resendApplication >=2.0}]]></conditionExpression>
    </sequenceFlow>
   
    <sequenceFlow id="flow9" sourceRef="rejectRequestDecision" targetRef="adjustVacationRequestTask">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${resendApplication <2.0}]]></conditionExpression>
    </sequenceFlow>
   
   
   
   
   
    <userTask id="adjustVacationRequestTask" name="Adjust appeal request">
      <documentation>
        Your manager has disapproved your appeal request for ${numberOfDays} days.
        Reason: ${managerMotivation}
      </documentation>
      <extensionElements>
        <activiti:formProperty id="numberOfDays" name="Number of days" type="long" required="true">${numberOfDays}</activiti:formProperty>
        <activiti:formProperty id="vacationMotivation" name="Motivation" type="string" >${vacationMotivation}</activiti:formProperty>
        <activiti:formProperty id="resendRequest" name="Resend vacation request to manager?" type="enum" required="true">
          <activiti:value id="Yes" name="Yes" />
          <activiti:value id="No" name="No" />
        </activiti:formProperty>
      </extensionElements>
      <humanPerformer>
        <resourceAssignmentExpression>
          <formalExpression>${requesterName}</formalExpression>
        </resourceAssignmentExpression>
      </humanPerformer> 
    </userTask>
    <sequenceFlow id="flow10" sourceRef="adjustVacationRequestTask" targetRef="resendRequestDecision" />
   
    <exclusiveGateway id="resendRequestDecision" name="Resend request?" />
     <sequenceFlow id="flow11" sourceRef="resendRequestDecision" targetRef="theEnd2">
      <conditionExpression xsi:type="tFormalExpression">${resendRequest=='No'}</conditionExpression>
    </sequenceFlow>
   
    <sequenceFlow id="flow12" sourceRef="resendRequestDecision" targetRef="handleRequest">
      <conditionExpression xsi:type="tFormalExpression">${resendRequest=='Yes'}</conditionExpression>
    </sequenceFlow>
   
    <endEvent id="theEnd2" />
  
    <sequenceFlow id="flow13" sourceRef="requestApprovedDecision" targetRef="giveInfoTask">
      <conditionExpression xsi:type="tFormalExpression">${ticketStatus == 'NeedInfo'}</conditionExpression>
    </sequenceFlow>
   
    <userTask id="giveInfoTask" name="Give More Info">
      <documentation>
        Your manager has asked for more info.
        Reason: ${managerMotivation}
      </documentation>
      <extensionElements>
        <activiti:formProperty id="numberOfDays" name="Number of days" type="long" required="true">${numberOfDays}</activiti:formProperty>
        <activiti:formProperty id="vacationMotivation" name="Motivation" type="string" >${vacationMotivation}</activiti:formProperty>
        <activiti:formProperty id="moreinfo" name="more info" type="string" required="true"/>
        <activiti:formProperty id="sendinfo" name="Send More Info?" type="enum" required="true">
          <activiti:value id="Yes" name="Yes" />
          <activiti:value id="No" name="No" />
        </activiti:formProperty>
      </extensionElements>
      <humanPerformer>
        <resourceAssignmentExpression>
          <formalExpression>${requesterName}</formalExpression>
        </resourceAssignmentExpression>
      </humanPerformer> 
    </userTask>
   
    <sequenceFlow id="flow14" sourceRef="giveInfoTask" targetRef="moreinfodecision" />
   
    <exclusiveGateway id="moreinfodecision" name="Send Info?" />
    <sequenceFlow id="flow15" sourceRef="moreinfodecision" targetRef="handleRequest">
      <conditionExpression xsi:type="tFormalExpression">${sendinfo == 'Yes'}</conditionExpression>
    </sequenceFlow>
   
     <sequenceFlow id="flow16" sourceRef="moreinfodecision" targetRef="theEnd4">
      <conditionExpression xsi:type="tFormalExpression">${sendinfo == 'No'}</conditionExpression>
    </sequenceFlow>
    <endEvent id="theEnd4" />
   
      <!– <boundaryEvent id="timer" name="Timer" attachedToRef="initiateAppealRequest" cancelActivity="true">
          <timerEventDefinition>
              Fire remainder every monday at 8 am
              <timeCycle>0 0 8 ? * MON</timeCycle>
              <timeDuration>2013-07-08T04:40:00</timeDuration>
          </timerEventDefinition>
      </boundaryEvent> –>
    <!– <sequenceFlow id="flow17" sourceRef="timer30days" targetRef="scripttask1"></sequenceFlow>
    <scriptTask id="scripttask1" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">
          <script><![CDATA[
          println("**********I am inside 30daystimer script task");
              
          ]]></script>
    </scriptTask>
   
    <sequenceFlow id="flow18" sourceRef="scripttask1" targetRef="myListenerTask"></sequenceFlow>
    <userTask id="myListenerTask" name="My Task Listener">
      <extensionElements>
       <activiti:taskListener event="end" class="com.getinsured.hix.tkm.activiti.MyTaskListener" />
      </extensionElements>
    </userTask>
    <sequenceFlow id="flowendmyListenerTask" sourceRef="myListenerTask" targetRef="theEnd7"></sequenceFlow>
    <endEvent id="theEnd7" />
   
    <sequenceFlow id="flow19" sourceRef="timer29days" targetRef="scripttask2"></sequenceFlow>
    <scriptTask id="scripttask2" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">
          <script><![CDATA[
          println("**********I am inside 29daystimer script task");
              
          ]]></script>
    </scriptTask>
    <sequenceFlow id="flowscripttask2" sourceRef="scripttask2" targetRef="notificationListener"></sequenceFlow>
    <userTask id="notificationListener" name="My NotificationListener Task ">
      <extensionElements>
       <activiti:taskListener event="end" class="com.getinsured.hix.tkm.activiti.NotificationListener" />
      </extensionElements>
    </userTask>
    <sequenceFlow id="flowendnotificationListener" sourceRef="notificationListener" targetRef="theEnd8"></sequenceFlow>
    <endEvent id="theEnd8" />
    <sequenceFlow id="flow20" sourceRef="timer23days" targetRef="scripttask3"></sequenceFlow>
    <scriptTask id="scripttask3" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">
          <script><![CDATA[
          println("**********I am inside 23daystimer script task");
              
          ]]></script>
    </scriptTask>
    <sequenceFlow id="flowendscripttask3" sourceRef="scripttask3" targetRef="theEnd9"></sequenceFlow>
    <endEvent id="theEnd9" /> –>
       
     
  </process>
 
</definitions>
5 REPLIES 5

frederikherema1
Star Contributor
Star Contributor
You should, instead, add a sub-process around the whole process you have now. Add the timer-boundary-event on the boundary of this subprocess, having cancelActivity=true. When the timer fires, all active tasks in the subprocess will be cancelled, resulting in only one active path of execution in your process, being the outgoing path from the timer-event.

The reason why your process doesn't work is because the process can only finish when all parallel paths are finished. If you fork the execution into 2 paths: 1) Regular tasks and 2) timer, both regular tasks should be completed as well as the timer…

Thanks for replying. For the first part of your answer my timer works fine when the process is not completed as  it gets triggered and that's what is expected  do you mean that it can not be achieved using intermediatecatchevent.
For the second part i am using parallel  gateway fork because i am need to have three different timers. Using time boundary event can i have three different timers.

frederikherema1
Star Contributor
Star Contributor
If you have a fork/join, the process only ends of ALL parallel paths have ended. So if you have 4 paths (1 normal and 3 with an intermediate-timer event in it) the process will only end if all 4 of those flows are complete… So what I understand from your use case, this is not possible this way.

You can have 3 boundary-timers on the same sub-process, that's no problem.

satyakamkaul
Champ in-the-making
Champ in-the-making
Hello, I am posting my question in the same post, i have created three boundary-timers on the same sub process as you said.
My cancelActiviti is true in the last timer. I need to perform some operations so i am using execution listener for that inside the script task.
But once inside the listener the flow does not come out and it keeps on entering the listener infinitely. Now if i dont use any listener for the last timer it correctly ends the process. The only line in the listener: runtimeService.deleteProcessInstance(delegateExecution.getProcessInstanceId(), "Canceled");
Could you please tell what is wrong.
Here is the xml:
<boundaryEvent id="timer1" name="Timer1" attachedToRef="subProcess" cancelActivity="false">
          <timerEventDefinition>
              <timeDuration>PT80S</timeDuration>
          </timerEventDefinition>
      </boundaryEvent>      
      <boundaryEvent id="timer2" name="Timer2" attachedToRef="subProcess" cancelActivity="false">
          <timerEventDefinition>
              <timeDuration>PT140S</timeDuration>
          </timerEventDefinition>
      </boundaryEvent>      
      <boundaryEvent id="timer3" name="Timer3" attachedToRef="subProcess" cancelActivity="false">
          <timerEventDefinition>
              <timeDuration>PT180S</timeDuration>
          </timerEventDefinition>
      </boundaryEvent>       
    <sequenceFlow id="flow1245" sourceRef="timer1" targetRef="scripttask1"/>
    <scriptTask id="scripttask1" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">
          <extensionElements>
      <activiti:executionListener class="com.getinsured.hix.tkm.activiti.NotificationListener" event="end">
       </activiti:executionListener>
        </extensionElements>
          <script><![CDATA[
          println("**********I am inside script task1");
              
          ]]></script>
    </scriptTask>
    <sequenceFlow id="flow12456" sourceRef="timer2" targetRef="scripttask2"/>
    <scriptTask id="scripttask2" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">
       <extensionElements>
      <activiti:executionListener class="com.getinsured.hix.tkm.activiti.NotificationListener" event="end">
       </activiti:executionListener>
        </extensionElements>
          <script><![CDATA[
          println("**********I am inside script task2");
              
          ]]></script>
    </scriptTask>
    <sequenceFlow id="flow12457" sourceRef="timer3" targetRef="scripttask3"/>
    <scriptTask id="scripttask3" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">
     <extensionElements>
    <activiti:executionListener class="com.getinsured.hix.tkm.activiti.MyTaskListener" event="end">
       </activiti:executionListener>
     </extensionElements>
          <script><![CDATA[
          println("**********I am inside script task3");
              
          ]]></script>
    </scriptTask>
    <sequenceFlow id="flow124587" sourceRef="scripttask3" targetRef="theEndAll"/>
    <endEvent id="theEndAll" />

mmaker1234
Champ in-the-making
Champ in-the-making
Instead to remove the listener, try to do  something else in it, for example <code>System.err.println("Going to complete process instance" + delegateExecution.getProcessInstanceId() );</code> and monitor what happens.