cancel
Showing results for 
Search instead for 
Did you mean: 

Get Previous Task Information

muratto12
Champ in-the-making
Champ in-the-making
Hi,

How can I get previous task's Id or Information on a task? (by a execution listener, etc.)

Thanks
7 REPLIES 7

nils1
Champ in-the-making
Champ in-the-making
Hi, can you elaborate on what exactly you are looking for? You might be looking for the HistoryService.

Cheers,
Nils

muratto12
Champ in-the-making
Champ in-the-making
Users want to see who completed the previous task.

trademak
Star Contributor
Star Contributor
Hi,

As Nils said, this can be done via the HistoryService.
Just look in the Javadoc for more details.

Best regards,

muratto12
Champ in-the-making
Champ in-the-making
Hi,

I'll try it with HistoryService.

Also, how would history service behave in these 2 scenarios.

1. a multi instance task as a first step, and a task as a second step
2. two tasks joined at a paralel gateway as a first step, and a task as a second step

What would be the previous task in these cases.  There are not only one previous task in these cases.

Thanks

muratto12
Champ in-the-making
Champ in-the-making
I added a sample diagram for the second situation.

Which one would be the previous task at User Task 3 according to the historyService

chris_joelly
Champ in-the-making
Champ in-the-making
i think u need to give the HistoryService a hint on what could be the previous task connected to the task where u want to get the information, because a process instance can have many execution paths which do not nessessarily lead to your user task 3.

i use the following to get the task which was cancelled using a timer boundary listener when the sequence flow is taken via a execution listener on the sequence flow:

@Named
@Stateless
public class EscalationListener {

@Inject
HistoryService historyService;

public void escalate(DelegateExecution execution, String otherTaskId)
   throws Exception {

  HistoricTaskInstance task = historyService
    .createHistoricTaskInstanceQuery()
    .processInstanceId(execution.getProcessInstanceId()).
    .taskDefinitionKey(otherTaskId).singleResult();

                // do some stuff with the task
}
}

<sequenceFlow id="flow13" name="" sourceRef="boundarytimer1" targetRef="servicetask2">
      <extensionElements>
        <activiti:executionListener event="take" expression="#{escalationListener.escalate(execution, 'usertask2')}"></activiti:executionListener>
      </extensionElements>
</sequenceFlow>

The task to which the boundary timer is attached to is 'usertask2' and for this i want to get the task instance of the running process instance.

In your case u will need to give all your task ids (usertask1, usertask2, …) to the executionListener expression and within the execution listener u can use the history service to get their task end time with task.getEndTime() and decide which one u want to work with, e.g. by putting all task instances in a list and use a comparator based on the end date to sort them to your needs…

hth

muratto12
Champ in-the-making
Champ in-the-making
Thank you very much for answers.