AnsweredAssumed Answered

Start and access new process instance from running process

Question asked by flurina on Nov 26, 2013
Latest reply on Nov 27, 2013 by flurina
After upgrading from Activiti 5.10 to 5.14 we're facing a problem with a ScriptTask of a running process that needs to start another ProcessInstance.
As you can see in the code below, we want to start a new ProcessInstance and afterwards access its first task to add a CandidateGroup to it.

RepositoryService runtimeService = ActivitiUtil.getRuntimeService();
TaskService taskService = ActivitiUtil.getTaskService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MyProcess");

Task firstTask = taskService.createTaskQuery().executionId(processInstance.getProcessInstanceId()).singleResult();

It all worked fine while we were using Activiti 5.10 but ever since we upgraded to 5.14 we get a NullPointerException when calling addCandidateGroup, because the TaskQuery doesn't return anything. It worked with version 5.10 and still does in the JUnit-Test. Since we haven't changed anything else but upgraded to 5.14, we're assuming that there is no problem with the started process itself, but rather the time of the flush. It seems to us that the Activiti-Engine executes the flush after the script task is finished. We would need it to be executed right after calling startProcessInstanceByKey though. Is there any way to achieve that? Or do you know another approach of how to start a new process and access it from within a running process?

Thank you in advance,