# Generating another process Instance

**URL:** <https://forum.flowable.org/t/generating-another-process-instance/11743>\
**Category:** Uncategorized\
**Created:** [August 27, 2024, 8:54am UTC](https://forum.flowable.org/t/generating-another-process-instance/11743 "2024-08-27T08:54:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kartik](https://avatars.discourse-cdn.com/v4/letter/k/e274bd/32.png) [@kartik](https://forum.flowable.org/u/kartik)\
**Post date:** [August 27, 2024, 8:54am UTC](https://forum.flowable.org/t/generating-another-process-instance/11743/1 "2024-08-27T08:54:20Z")

</div>

hi all,  
In flowable i have task as  
ParentProcess  
start-\>user1-\>user2-\>callActivity  
SubProcess(call Activity)  
start-\>user1-user2-\>end

Now lets say i complete the user1 and user2 task and move to the callActivity This is possible  
but its also making another process Instance Id as  
user1 task completed  
user2 task not completed

Why is that happening?

My backend code is

public class FlowableService {  
@Autowired  
private RuntimeService runtimeService;  
@Autowired  
private TaskService taskService;  
@Autowired  
private RepositoryService repositoryService;  
@Autowired  
private SubProcessBusinessKeyGenerator subProcessBusinessKeyGenerator;

```
public void startprocess(String orderId){
    Map<String,Object> variables=new HashMap<>();
    variables.put("businessKey",orderId);
    ProcessDefinition processDefinition=repositoryService.createProcessDefinitionQuery().processDefinitionKey("startprocess").singleResult();
    ProcessInstance instance=runtimeService.startProcessInstanceById(processDefinition.getId(),orderId,variables);
  
    System.out.println("The process Instance Id "+Instance.getProcessInstanceId());
}
public List<WorkflowTask> getTask(String orderId, Map<String,Object> variables){

    List<WorkflowTask> task=taskService.createTaskQuery().processInstanceId(getProcessInstanceId()).list();
    taskService.setVariables(task.get(0).getId(),variables);
    return task;
}
public void completeTask(String taskId){
    taskService.complete(taskId);
}

```

}

 ![Screenshot 2024-08-27 142248](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/e/efd7e4a49bb25b3f7847394193dd75703ed240c6.png)

As you can see it has created the process Instance when i have already completed all the task and moved to the callActivity

Please do tell me what are the reasom why it creates another processInstamces

---

<div class="post-metadata">

**Author:** ![WelschChristopher](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/welschchristopher/32/2822_2.png) [@WelschChristopher](https://forum.flowable.org/u/WelschChristopher)\
**Post date:** [August 27, 2024, 9:04am UTC](https://forum.flowable.org/t/generating-another-process-instance/11743/2 "2024-08-27T09:04:00Z")

</div>

Hey, can you also show your bpmn files?

Multiple remarks:

> ```
> ProcessDefinition processDefinition=repositoryService.createProcessDefinitionQuery().processDefinitionKey("startprocess").singleResult();
> 
> ```

Will crash as soon as you create a new deployment for the same process key.

> runtimeService.createProcessInstanceBuilder().processDefinitionKey(“yourKey”).businessKey(orderId).variables(variables).start();

might be better for your use case.

The other question:  
Why are you setting the variables of a task within your getTask method? You are only updating the first task, but the task query returns a list of tasks.

Greetings

Christopher
