Create new processInstances at runtime with parent/child relationship

Hi,

I have to model a typical order - orderItem scenario in activiti:

A process instance is started with some Order Object Variable - containing a list of orderItems. Each orderItem should be handled in its own ProcessInstance.

So I started to model a Parent ProcessDefinition with a MultiInstance CallActivity, which calls the Child ProcessDefinition containing the workflow logic for the OrderItem, but this only starts an execution for each orderItem - not a new ProcessInstance (for us, the problem with executions is, that they can not be monitored by our system).

Is it possible to create new Child ProcessInstances at runtime and keep the parent/child relationship (so that I can query the child process instances with the superProcessInstanceId?

I also have the requirement, that the Parent ProcessInstance should do some final Logic, wenn all Child Process are finished.

That should be how it is, when using a callactivity. Do note that a process instance is an execution too.
What query are you using to retrieve the process instances?

The default behaviour of the multi instance is to wait for all the instances (can be tweaked by changing the completion condition). Whatever is after the multi instance, will be done when these instances have finished.

When using the callactivity, I find the “subprocess instances” via

List<Execution> list = this.getRuntimeService().createExecutionQuery().processInstanceId(processInstanceParentId).list();

This list contains various Executions, the subprocess executions but perhaps also more executions (e.g. the subprocess itself can also have more executions or the parent process could also have more Executions). So with this query, I can not find out, what my subprocess instances are.

What I want is to find the “subprocess instances” as ProcessInstances via

List<HistoricProcessInstance> list = this.getHistoryService().createHistoricProcessInstanceQuery().superProcessInstanceId(processInstanceParentId).list();

Here, I get an empty List.
In what case do I find HistoricProcessInstances when I filter for ‘superProcessInstanceId’?

A subprocess will have a superProcessInstanceId, other executions won’t.

That should work. We’ve got unit tests that verify this (see for example flowable-engine/HistoryServiceTest.java at 6bfadc02465f0b5e95aa61390b10f6fbe4759e7c · flowable/flowable-engine · GitHub). So not sure what’s going wrong here … do you see in the database that the super process instance id has the correct value?