Can not startBeforeActivity at an activity defined in a subprocess

I have a parent process where a subprocess is started with “callActivity”. The subprocess contains two tasks, task1 and task2. When I try to start the parentProcess at “task2”, I get a NotValidException:

org.camunda.bpm.engine.exception.NotValidException: Element 'task2' does not exist in process parentProcess:1:324: targetElement is null
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at org.camunda.bpm.engine.impl.util.EnsureUtil.generateException(EnsureUtil.java:380)
    at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:54)
    at org.camunda.bpm.engine.impl.cmd.StartProcessInstanceAtActivitiesCmd.determineFirstActivity(StartProcessInstanceAtActivitiesCmd.java:123)
    at org.camunda.bpm.engine.impl.cmd.StartProcessInstanceAtActivitiesCmd.execute(StartProcessInstanceAtActivitiesCmd.java:69)
    at org.camunda.bpm.engine.impl.cmd.StartProcessInstanceAtActivitiesCmd.execute(StartProcessInstanceAtActivitiesCmd.java:46)
    at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:27)
    at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:106)
    at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:69)
    at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
    at org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl.executeWithVariablesInReturn(ProcessInstantiationBuilderImpl.java:165)
    at org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl.execute(ProcessInstantiationBuilderImpl.java:131)
    at org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl.execute(ProcessInstantiationBuilderImpl.java:127)

Here is how I try to start the process at “task2”.

runtimeService.createProcessInstanceByKey("parentProcess")
    .startBeforeActivity("task2")
    .execute()

parentProcess.bpmn (2.2 KB)

subProcess.bpmn (2.7 KB)

To contextualize a little: we need to migrate old process instances into new definition, so we need to be able to start at any user task in the process.

Am I missing something ?
Thanks

Hi @Hugo_Gerard,

task1 doesn’t exist in parentProcess. It is an activity of subProcess. So try the following invoke

runtimeService.createProcessInstanceByKey("subProcess")
    .startBeforeActivity("task1")
    .execute()

Hi, I actually need an instance of the parentProcess. In the real process, there are other activities following the callActivity(subProcess) in the parentProcess.

Something like this:

26

So I would need this instance tree:

parentProcess
    subProcess
        task1

So when task1 and task2 are complete, the parent process continue.
Thanks for your time.!

Then … Did you try to start before the callActivity “callSubProcess” instead of task1

runtimeService.createProcessInstanceByKey("parentProcess")
    .startBeforeActivity("callSubProcess")
    .execute()

Yes, but that would not work if I need to start before “task2”. This need is part of a bigger migration process where I would need to start at any task in the workflow. I reformulate my topic.

Hugo, did you ever find a resolution for this? I have the same scenario, I want to Start a process, containing called sub-processes at an activity within the sub-process.

I suspect it may be a two-step solution, first Starting the parent a the sub-process and then Modifying the sub-process to place the token in the right position.

There is not out of the box way to do that with “call activity”.

Ryan Johnston on stackoverflow suggested to create the subprocess in a service task but you loose the parent/subprocess link, unless I missed something.

Your two-step solution might be the one to go. How do you modify the subprocess instance ?

Depending on the circumstances of the subprocess I will either Complete Tasks or send the appropriate Messages and/or Variables to get me where I want. My case is fairly simple, but I could see that being problematic if you don’t want intermediate tasks to fire within the subprocess.