cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically assigning task to users

sambit
Champ in-the-making
Champ in-the-making
Activiti Version: 5.12.

We have a need, for an admin to view all user tasks under a bpmn model file and assign each task to suitable user. For this we have created an admin task. Please note, when admin person assigns tasks to users, tasks are not yet executed(i.e kind of future tasks). After admin complete his job, each user should login to their UI screen and compelte task. We have our own UI framework for Admin and user pages.

Q: how to allow the admin person to assign the future tasks ?
Following code snippet is used to query all tasks
      String processDefinitionID = rtService
      .createProcessInstanceQuery().list().get(0).getProcessDefinitionId();
      BpmnModel bpmnmodel = reposService.getBpmnModel(processDefinitionID);
      List<Process> processes = bpmnmodel.getProcesses();
      for(Process indivProcessSmiley Tonguerocesses){
         List<UserTask> userTasks = indivProcess.findFlowElementsOfType(UserTask.class);
         for(UserTask userTask:userTasks){
            System.out.println("Task=" + userTask.getName() + "; TaskAssignee=" + userTask.getAssignee()+"\n");            
         }
      }

however    userTask.setAssignee(userName); does not see to work.

Kindly suggest.

Thanks
Sambit
5 REPLIES 5

frederikherema1
Star Contributor
Star Contributor
You should either use:

taskService.setTaskAssignee(…)

or use:

task.setAssignee(…);
taskService.saveTask(task.getId());

sambit
Champ in-the-making
Champ in-the-making
Does
"taskService.setTaskAssignee(…)

or use:

task.setAssignee(…);
taskService.saveTask(task.getId());"

work for the assigning the tasks which are not yet executed in the flow ? I mean activiti wont have generated taskIds by the time user assignments are being performed.

So if the flow looks like this

X–(user task1)—(user task2)—(user task3)—()
before starting the process the admin should be able to see all list of tasks and assigning to users.

trademak
Star Contributor
Star Contributor
Before starting the process you only have the process definition available, because there's no process instance yet. So for your use case it would make sense to get the BpmnModel and show the list of tasks. Then when the user has chosen the assignees you can pass them to the process instance as process variables.

Best regards,

sambit
Champ in-the-making
Champ in-the-making
Thanks for the advise.

Pls suggestion how should I access the process variable? I am aiming to access them via expression on UserTask.

Thanks
Sambit

jbarrez
Star Contributor
Star Contributor
That's all in the docs … typically just do ${myVariable}