Unable to move subtask to next level

Hi Team

I have a very simple workflow where i have a start Event–>UserTask 1 (tasks are displayed to analyst)–>userTask 2( these are all tasks which are displayed to supervisor).

Now we have a seperate java process which creates subtasks at runitime programatically using TaskService.newTask. These tasks are added to main task (UserTask1) . All this subtasks are visible to Analyst user when he invoked TaskService.getTasks.
The analyst now marks the main task and its subtask as compete.
The task now moves to next step to Supervisor. The supervisor is able to see the task but he is unable to see the subtasks. Isee that when a task moves from analyst to supervisor , the taskId changes.

What code or configuration i have to do so that even subtasks are visible to Supervisor. I am using SpringBoot + Flowable. The subtasks are going to be created at runtime.

Can anyone please help ?

Additional informationon my usecase

I want to show few tasks to the user. Thiese tasks are going to be in dynamic number in nature .I.e sometimes it will show 5 , 10, 100 or 200 tasks.
But the user has to submit all tasks together. he cannot submit individual task to next level i.e his approver.
Hence i created a user Task 1 and i tried adding subtasks to it programatically at runtime using
Taskservice.newTask().setParentTaskId(parentTaskId i.e TaskId of userTask1).
When user submits userTask 1, the substaks added to this user task1 is not visible to supervisor.
May be becuase he is looking at user task 2 which is all together a new tasks.
How can i programatically send all these subtasks to supervisor. I want to maintain the lifcecycle of all these subtasks such as when it was created, when it was completed etc.

Thanks

I tried below code

@Override
public ProcessInstanceResponse taskCreate() {
Map<String, Object> variables = new HashMap<String, Object>();

    runtimeService= getProcessEngine().getRuntimeService();




    ProcessInstance processInstance =
            runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, variables);

    
    DynamicBpmnService dynamicBpmnService=getProcessEngine().getDynamicBpmnService();

    
	**/////////////////////////    create 3 new dynamic task ///////////////////////////**
	DynamicUserTaskBuilder taskBuilder = new DynamicUserTaskBuilder();
    

	
    taskBuilder
            .name("MyTempTaskName4").setId( "MyTempTaskName1");


    DynamicUserTaskBuilder taskBuilder1 = new DynamicUserTaskBuilder();


    taskBuilder1
            .name("MyTempTaskName6").setId("MyTempTaskName6");

    DynamicUserTaskBuilder taskBuilder2 = new DynamicUserTaskBuilder();


    taskBuilder2
            .name("MyTempTaskName7").setId("MyTempTaskName7");

// taskService.addCandidateGroup(subTask.getId(), TASK_CANDIDATE_GROUP_ANALYST);
dynamicBpmnService.injectUserTaskInProcessInstance(processInstance.getProcessInstanceId(), taskBuilder);

    dynamicBpmnService.injectUserTaskInProcessInstance(processInstance.getProcessInstanceId(), taskBuilder1);
    

    dynamicBpmnService.injectUserTaskInProcessInstance(processInstance.getProcessInstanceId(), taskBuilder2);
    


    procesInstanceId=processInstance.getId();


    taskService = getProcessEngine().getTaskService();
    List<Task> tasks1 =taskService.createTaskQuery().processDefinitionId(processDefnId).list();

    for(Task task: tasks1) {

        try {
            ObjectNode infoNode = dynamicBpmnService.changeUserTaskCandidateGroup(task.getId(), TASK_CANDIDATE_GROUP_ANALYST, true);

            taskService.addCandidateGroup(task.getId(),TASK_CANDIDATE_GROUP_ANALYST);
            dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
	
	**/////////////////////////   End  create 3 new dynamic task ///////////////////////////**
	
	
    processDefnId= processInstance.getProcessDefinitionId();

    //I get 4 task get here as i have added taskService.addCandidateGroup above. Seems dynamicBpmnService.changeUserTaskCandidateGroup is not working.
	//Once i complete all 4 tasks here, i want these tasks to be visible to supervisor but supervisor is sessing only 1 task.
	
	List<Task> tasks =taskService.createTaskQuery().processInstanceId(procesInstanceId).taskCandidateGroup(TASK_CANDIDATE_GROUP_ANALYST).list();
    //pcAnalystSubmit("1",true);

/////////////////////////mark task as complete///////////////////////
for (Task task : tasks) {

        taskService.complete(task.getId());
       // ObjectNode infoNode = dynamicBpmnService.changeUserTaskCandidateGroup(task.getId(), TASK_CANDIDATE_GROUP_SUPERVISOR, true);


        //taskService.addCandidateGroup(task.getId(),TASK_CANDIDATE_GROUP_ANALYST);
        //dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);

    }

//////////////////////////////I dont see all tasks here. I see only 1 task here.//////////////////////
tasks =taskService.createTaskQuery().processInstanceId(procesInstanceId).taskCandidateGroup(TASK_CANDIDATE_GROUP_SUPERVISOR).list();

I am not able to move all dynamic tasks from analyst to supervisor when they are marked as completed.

Any help appreciated !!

Why don’t you create multiple instances of task1 and then same move through the workflow to task 2 ?
I am unable to understand the need of sub task. Can you please share a hypothetical example?

Thanks @pahujadeepanshu. I have used multiinstance task to create task dynamically and the problem is fixed.

I have a simple scenario where an analyst submits task which goes to supervior and supervisor can accept the changes or reject the changes. If he accepts, than the workflow end. If he rejects, than pcanalyst again has to do rework.
For this i created a simple model

Start–>Pc Analyst User Task–> SuperVisor User Task–>Reject–> Gor back to Pc Analyst Task.

The flow works well but the poblem here is that when supervisor rejects, a new task is created for PC Analyst. Ideally i wanted the same task to be visible to PC Analyst on which he had worked on as it would have details such as his comments. Also i was saving PC Analyst task Id in DB before he submits the task and using it in many reports. Now because the taskId has changed after rejection, i am not able to show latest status of the task in the report as in my local DB i have old Task Id but in flowable i have a new task for PCAnalyst.
Do i need to change anything in my model ?

Prashant,

Think of it like a workflow. If tomorrow have a need to identify how many times the review was rejected, you will simply not have the information. In this case, you can just count the task instances from history and bang on.

Anything like comments, you can probably add global variables on the process and manage them. Remember to keep the scope of variable as process instance so that the variables are managed on each process instance.

I am using the same approach in my project.

Hope it helps.