cancel
Showing results for 
Search instead for 
Did you mean: 

Get execution id to signal a receiveTask in a subprocess

joachimvda
Champ in-the-making
Champ in-the-making
Hi,

I have a workflow which contains a subprocess (embedded). This subprocess contains a receiveTask.

I am writing a junit test in which I want to signal that receiveTask.
In my process I have set the businessKey when creating the process and I also have a process variable which contains that business key.

I cannot find a way to get the correct execution id to assure that the signal succeeds.

My first try was
runtimeService.createExecutionQuery().processInstanceBusinessKey(businessKey).singleResult())

but this causes a NPE as this return the process id of the parent process, not the subprocess.

I tried searching by doing a query on the super process:
ProcessInstance parentProcess = runtimeService.createProcessInstanceQuery()
                .processInstanceBusinessKey(businessKey(vorderingsopdracht))
                .singleResult();
        ProcessInstance subProcess = runtimeService.createProcessInstanceQuery()
                .superProcessInstanceId(parentProcess.getId())
                .singleResult();
        Execution execution = runtimeService.createExecutionQuery().
                    processInstanceId(subProcess.getId()).singleResult();

Unfortunately this fails as the superProcessInstanceId query returns no results.

The only way I found to find a working execution is using
runtimeService.createExecutionQuery().
                activityId("wachtenAfgewerkt").
                singleResult();

This obviously has the problem that I have a problem figuring out the correct execution if there is more than one.

What is the suggested way to find the correct execution object?

I am using 5.10-SNAPSHOT (as I am also using designer 5.9.2 and 5.9 does not recognize the .bpmn flows).
2 REPLIES 2

trademak
Star Contributor
Star Contributor
Hi,

An embedded sub process is only a container in the process definition, not a process definition on itself.
If you would want that you need to use a call activity and a standalone sub process.
So your code is actually the way to approach this:

runtimeService.createExecutionQuery().
                activityId("wachtenAfgewerkt").
                singleResult();

But you can extend this query with a specific processInstanceId or processDefinitionKey value to get the right instance.

Best regards,

borovinskih
Champ in-the-making
Champ in-the-making
Had similar problem and the solution was:
<java>
.processInstanceBusinessKey(businessKey, true)
</java>
to include child executions.