cancel
Showing results for 
Search instead for 
Did you mean: 

timer boundary event and expired activity

mandas
Champ in-the-making
Champ in-the-making
Dear all,

Is there any way, in the context of timer boundary event (cancelActiviti=true) or in its outgoing transition, to catch the activiti id of the expired activiti? I have an expired task and I need access to the task id. Alternatively, is a deterministic historic query to get it?

Thanks,
Dimitris
6 REPLIES 6

frederikherema1
Star Contributor
Star Contributor
The history of the activities are not yet committed to the database at the time the boundary-event is triggered. However, when not canceling the activiti, the parent-execution (containing the activityId of the task that is currently active in that execution) is available. You can use the DelegateExecution (casted to ExecutionImpl) to call "public ExecutionImpl getParent()" (or subsequently parent of parent in case of boundary-event on sub-processes).

Does this help?

mandas
Champ in-the-making
Champ in-the-making
Actually we definitely need to cancel the activiti. So, to my understanding, in that transactional context the user task will have been deleted. What I 'm doing is adding another service task after the timer (async=true) and do the following :

<code>
HistoricTaskInstance expiredTask = historyService.createHistoricTaskInstanceQuery()
         .processInstanceId(execution.getProcessInstanceId())
         .finished()
         .taskDeleteReason("deleted").singleResult();
</code>

However this works in our case because that task we are querying is the only task in the process. I 'll try with cancel activiti to false and delete the task in the listener after the expiration timer and I 'll let you know.

Thanks
Dimitris

mandas
Champ in-the-making
Champ in-the-making
Actually, my initial question was wrong. I 've falsely written about activiti id (which can be get from the execution either with cancel=true or false). My need is to get the task id of the expired task, is this possible?

Sorry for the inconvenience,
Dimitris

jbarrez
Star Contributor
Star Contributor
Do you mean the task id in the xml definition? Or the database id of the task?

I assume the database id. I don't see an easy way to retrieve that id straight away. Probably with a BpmnParseHandler on the timer you might be able to store the id on which the timer is defined. But it's a long shot.

mjacobi
Champ in-the-making
Champ in-the-making
I have had a quite similar requirement. What I did in order to have the taskID available, was to add a taskListener to the user task. I used the <code>ScriptTaskListener</code> for the task-<code>create</code> event. See the following example:

<blockcode>
<userTask id="T0" name="T0" activiti:assignee="kermit">
      <extensionElements>
        <activiti:taskListener event="create" class="org.activiti.engine.impl.bpmn.listener.ScriptTaskListener">
         <activiti:field name="script">
          <activiti:string>
     tid = task.getId(); // test access to task instance
    </activiti:string>
         </activiti:field>
     <activiti:field name="language" stringValue="groovy" />
    </activiti:taskListener>
      </extensionElements>
    </userTask>
</blockcode>

Now you have the taskID available in the instance variable <code>tid</code>.
Cheers

frederikherema1
Star Contributor
Star Contributor
That's a valid solution that mjacobi suggests and requires no actual java-coding..