1
votes

I have a requirement where I need to set assignee's to all the "user-tasks" in a process instance as soon as the instance is created, which is based on the candidate group set to the user-task.

i tries getting the user-tasks using this :

Collection<UserTask> userTasks = execution.getBpmnModelInstance().getModelElementsByType(UserTask.class);

which is correct in someway but i am not able to set the assignee's , Also, looks like this would apply to the process itself and not the process instance.

secondly , I tried getting it from the taskQuery which gives me only the next task and not all the user-tasks inside a process.

Please help !!

1

1 Answers

3
votes

It does not work that way. A process flow can be simplified to "a token moves through the bpmn diagram" ... only the current position of the token is relevant. So naturally, the tasklist only gives you the current task. Not what could happen after ... which you cannot know, because if you had a gateway that continues differently based on the task outcome? So drop playing with the BPMN meta model. Focus on the runtime.

You have two choices to dynamically assign user tasks:

1.) in the modeler, instead of hard-assigning the task to "a-user", use an expression like ${taskAssignment.assignTask(task)} where "taskAssignment" is a bean that provides a String method that returns the user. 2.) add a taskListener on "create" to the task and set the assignee in the listener.

for option 2 you can use the camunda spring boot events (or the (outdated) camunda-bpm-reactor extension) to register one central component rather than adding a listener to every task.