Hi Tijs,
Yes, it does not help in this case since the parent execution of the user task execution is the process execution and not the subprocess execution. I was surprised at the fact that there isn't a "subprocess" execution in this case. I'm wondering if that is a result of how my test template is defined. I've attached a copy of it. Note there are no UserTasks or Service Tasks in the process. The process simply flows directly into the subprocess.
I was able to make this work in the following way:
1) Override DefaultActivityBehaviorFactory.createSubprocActivityBehavior() method to return a custom class which has a field that stores the id of the subprocess from the template.
1) In the execute method of the custom SubProcessActivityBehavior class set the subprocess id in a local variable.
2) Update the VARIABLE_UPDATED event listener class to find the scope for a subprocess using the local variable and the process definition. For example:
String subprocessDefinitionId = (String)executionEntity.getVariableLocal(Constants.SUBPROCESS_DEFINITION_ID);
scope = executionEntity.getProcessDefinition().findActivity(subprocessDefinitionId);
I'm still testing. But this seems to be working for us.
Is there an alternative approach that wouldn't require us to create a local variable?