cancel
Showing results for 
Search instead for 
Did you mean: 

Querying ProcessInstance on PROCESS_COMPLETED events

ravenblackdusk
Champ on-the-rise
Champ on-the-rise

I'm trying to handle a PROCESS_COMPLETED event by creating an ActivityEventListener bean:

   @Override
    public void onEvent(ActivitiEvent event) {

         final ProcessInstance processInstance = event.getEngineServices().getRuntimeService()
                .createProcessInstanceQuery().processInstanceId(event.getProcessInstanceId())
                .includeProcessVariables().singleResult();

   }

first of all event.getProcessInstanceId() returns an id that does not exist in the database, second ProcessInsantceQuery seems to only return process instances that are not completed(hence processInstance == null). My goal is to get the variables of every process instance that is completed. how can I achieve this?

1 REPLY 1

ravenblackdusk
Champ on-the-rise
Champ on-the-rise

I was able to get the variable I wanted like this:

   String var = (String) ((ExecutionEntity) ((ActivitiEntityEventImpl) event).getEntity()).getVariable("var");

And I noticed that the id returned by event.getProcessInstanceId() will exist in the database after event handling is finished. Perhaps only the history of the process instance is saved in that table. My problem is fixed; but still it would be nice to be able to query finished process instances and unfinished alike.

Getting started

Explore our Alfresco products with the links below. Use labels to filter content by product module.