Querying ProcessInstance on PROCESS_COMPLETED events

cancel
Showing results for 
Search instead for 
Did you mean: 
ravenblackdusk
Active Member

Querying ProcessInstance on PROCESS_COMPLETED events

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
ravenblackdusk
Active Member

Re: Querying ProcessInstance on PROCESS_COMPLETED events

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.