Start a process instance in a specific task

Hello,

Is There a way to start a process in a different point of the flow? example:

Start --> fristUserTask --> secondUserTask --> thirdUserTask --> End

If I create a new instance of the Procces above, the active activity will be “fristUserTask”. But if for some reason I want to start a new Instance and in the same way I want to the active activity to be “thirdUserTask”, will flowable engine support this kind of behavior?

I have a lot of legacy process running outside of engine and I’d like to start in different points depending of process.

Thanks.

Yes, this is possible, have a look at https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/runtime/RuntimeServiceTest.java#L1806

It’s a low level api at the moment, but in that test (and others in the same class) you can get an idea of how it looks currently. But it will get more love in the coming months.

Hi, I just looked at this and do not think it is what the op was looking for. Yes, the change activity builder can change the state of a process to any state that you want. However to do that you need a process instance. And the only way to create a process instance is to start a new instance which will execute your first task and all synchronous tasks following it.
How do I create a process instance in a non-start state?

Right now you can’t. At least not through the API. Using a custom Command you could do it, by creating a process instance execution and a child execution in the start event . But not sure how the change activity builder would react to that, would need to verify that.

Hi Joram, thanks for your reply. Would you have an example or more pointers on what to do exactly?

A custom Command can be used when there’s no out-of-the-box API to do what you want. You execute a command through the managementService#executeCommand method: https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/main/java/org/flowable/engine/ManagementService.java#L370

In such a Command, you are effectively ‘below’ the API level and have access to all internal services. Simple example: https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/mgmt/JobQueryTest.java#L197

In this particular use case, you’d use the ExecutionEntityManager to create an execution for the process instance and one for the start event, link it with the right process definition and then call the change activity logic.