无法在子流程中定义的 activity 处启动 BeforeActivity

Can not startBeforeActivity at an activity defined in a subprocess

我有一个子进程以 "callActivity" 启动的父进程。子流程包含两个任务,task1 和 task2。当我尝试在 "task1" 或 "task2" 处启动 parentProcess 时,我得到一个 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)

以下是我尝试在 "task2" 开始该过程的方法。

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

稍微考虑一下上下文:我们需要将旧流程实例迁移到新定义中,因此我们需要能够从流程中的任何用户任务开始。

我错过了什么?

如果我没看错您的问题,您似乎正试图在仅在(子)子流程定义中有效的步骤中启动父流程定义的实例。对吗?

如果是这样,那么您看到的行为就是预期的行为,您需要在父进程定义中指定 activity。

一旦在父实例中遇到子进程调用,您可以利用一些选项在特定步骤启动子进程实例,但 Call Activity 不支持这些选项,并且需要通过 Java API 调用发生,可以在服务任务或脚本任务中完成。