cancel
Showing results for 
Search instead for 
Did you mean: 

Unique id of activity instance

stefanhenke
Champ in-the-making
Champ in-the-making
Hi,
I implemented an execution listener which is configured for service and user tasks. I want to notify some component about each task that has been started and completed. Beside the activity id, this call should include a unique id of the activity instance so that the callee can distinguish between the activity instances (e.g. if they have been executed in a loop). From the DelegateExecution interface which is being passed by activiti, I cannot find this information. Am I missing something here?
Only by sending a HistoricActivityInstanceQuery to the HistoryService, I´m somehow able to get the information. However, I don´t know if it is reliable to send such a query within an execution listener.
Any hints?
Best regards,
Stefan

1 REPLY 1

motorina0
Confirmed Champ
Confirmed Champ
Hi Stefan,

  I could not find how to get the Activity Instance ID from a listener, but for tasks is quite simple to fetch the taskID:

The listener class:
<java>
import org.activiti.engine.delegate.DelegateTask;

public class ListenToTask {

  public void logUserTaskEvent(DelegateTask delegateTask, String eventName) {
    System.out.println("!!!! task created: " + delegateTask.getId());
  }
}
</java>

The BPMN listener:
<code>
    <userTask id="check_status" name="Check Status">
   <extensionElements>
        <activiti:taskListener event="create" expression="${userTaskListener.logUserTaskEvent(task, task.eventName)}"></activiti:taskListener>
      </extensionElements>
    </userTask>
</code>

The bean:
<code>
<bean id="userTaskListener" class="org.activiti.demo.delegate.ListenToTask"/>
</code>

The output:
<code>
!!!! task created: 15011
!!!! task created: 15018
!!!! task created: 15024
</code>

I have also pushed the samples here:
https://github.com/motorina0/activiti/blob/master/samples/ten-minute-demo/src/main/java/org/activiti...