In short, I start a process that happily follows a few steps before it hits a 'wait' state where it's persisted to db. At some point, i have to derive by the rules if any other sub-processes have to be created. Since jbpm provides an option to create only 1 subprocess at a given step, I'm openning subprocesses programmatically, i.e. in CreateSubprocesses activity handler:
{code}
//calculate groups to assign to a swimlane
taskAssignees = ...;
assigneeGroups.put(SharedConstants.KEY_SWIMLANE_CANDIDATE_GROUPS, taskAssignees);
ProcessInstance processInstance = executionService.startProcessInstanceByKey("subprocess_1", assigneeGroups);
{/code}
Again, all of the above is done in an activity handler of the process that has just been instantiated and hasn't been saved to db yet.
Here's a shortened version of my jpdl:
{code:xml}
<process key="main" name="main" xmlns="http://jbpm.org/4.3/jpdl">
<start g="5,23,48,48" name="start">
<transition g="141,46:-88,-15" name="open.case" to="Create sub-process"/>
</start>
<state g="306,193,148,52" name="Wait For Update">
<transition g="-23,-24" name="end" to="end1"/>
</state>
<custom g="239,26,138,52" name="Create sub-process" class="CreateSubprocesses">
<transition g="484,52:-108,-17" name="to-split-paths" to="Wait For Update"/>
</custom>
<end g="566,493,48,48" name="end1"/>
</process>
{/code:xml}
and one of possible sub-processes (simplified):
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<process name="test" key="test" xmlns="http://jbpm.org/4.3/jpdl">
<swimlane candidate-groups="#{assigned.responsibilities}" name="assigned-group"/>
<start name="start1" g="16,21,48,48">
<transition name="to task1" to="task1" g="-17,-20"/>
</start>
<end name="end1" g="219,17,48,48"/>
<task name="task1" g="96,16,92,52" swimlane="assigned-group">
<transition name="to end1" to="end1" g="-20,-19"/>
</task>
</process>
{/code:xml}