Start a process instance in a specific task

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
willian_assoni
Member II

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 activiti 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.

2 Replies
mgundrum
Active Member

Re: Start a process instance in a specific task

Hey willian, 

I wonder if perhaps you could add a simple form task to the beginning of your workflow with a dropdown field to choose the starting point of your workflow. You could then use the sequence flows to determine which task is executed after the start with logic like 'if (startingpointdropdown = second)'. It might look something like this:

willian_assoni
Member II

Re: Start a process instance in a specific task

hi Mitch Gundrum, thanks for you help,

I found another solution using activiti api, I just share if anyone needs it in the future:

 

public class StartProcessIntoActivity implements Command<ExecutionEntity>, Serializable {
        private static final long serialVersionUID = 1L;
        private String businessKey;
        private String processKey;
        private String initialActivity;
        private Map<String, Object> variables ;

        public StartProcessIntoActivity(String processKey, String businessKey, String initialActivity, Map<String, Object> variables) {
             this.businessKey = businessKey;
             this.initialActivity = initialActivity;
             this.processKey = processKey;
            this.variables = variables;
       }

       @Override
       public ExecutionEntity execute(CommandContext commandContext) {
                  DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager();
                 ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedLatestProcessDefinitionByKey(processKey);
                 ActivityImpl initial = processDefinition.getActivities().stream().filter(f -> f.getId().equalsIgnoreCase(initialActivity)).findFirst().orElse(null);
                 

                 ExecutionEntity processInstance = processDefinition.createProcessInstance(businessKey, initial);
                 processDefinition.setVariables(variables);
                 processInstance.start();

                return processInstance;
       }
}


Just call the command using:
                managementService.executeCommand(new StartProcessIntoActivity("_123456", businessKey, "Task_1f6r24w",variables))


Thanks