Retrieving process variables by passed events

Hello,

in Check whether intermediate none event was passed I asked how to check whether an event has been passed in a process. Now I have a more complex issue concerning this:

  • I have a subprocess that contains an event called “Collaboration not required”. The subprocess is of type multi instance and has an element variable of a collection. For each element of the collection, a subprocess is started.
  • Now I want to retrieve the element variables of those sub processes in which the event “Collaboration not required” has been passed.

To retrieve the passed events, I could use something like this:

List listOfHistoryMilestones = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(processInstance.getId())
.activityId(ProcessConstants.MILESTONE_COLLABORATION_NOT_REQUIRED)
.finished()
.list();

To retrieve the historic element variables of the subprocesses, I could use something like this:

List list = historyService.createHistoricVariableInstanceQuery()
.variableName(ProcessConstants.VAR_NAME_MULTI_INSTANCE_ELEMENT)
.processInstanceId(processInstance.getId())
.list();

Now how do I connect those two things, i.e. how do I retrieve the variables of the subprocesses belonging to the milestones above? I tried to use the executionId of the event but that didn’t work.

Thank you for your help :slight_smile:

Does nobody have an idea? :neutral_face:

You can correlate them via activity instance IDs, although this may not be straightforward. I think you have to map the element variables into the subprocess via an input parameter, such that the element is set in the scope of the subprocess. HistoricVariableInstance#getActivityInstanceId will then return the activity instance ID of the respective subprocess instance. This should then match HistoricActivityInstance#getParentActivityInstance, since the subprocess instance is the parent activity instance of the milestone event.

Cheers,
Thorben

Hello @thorben,

thank you for your help! Unfortunately, it didn’t work:

  • I mapped the element variable into the subprocess as input parameter
  • The HistoricVariableInstance#ActivityInstanceId returns 38692491-318b-11e8-997e-341420524153 (Element variable of subprocess)
  • The HistoricActivityInstanceEntity#ParentActivityInstanceId returns SubProcess_0buo0vq:386a3635-318b-11e8-997e-341420524153 (milestone of subprocess)

Any idea?

Can you maybe share an executable test on github where you implemented this approach? I can then give it a look and see if I can make it work. This repo can help you get started: https://github.com/camunda/camunda-engine-unittest

Cheers,
Thorben