Set camunda candidate groups for user task with java api

Hi,
is it possible to set the candidate groups for a user task from the java api?
I’ve been loading the created tasks from my bpm with

Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

But I’ve only found the method to set the assignee directly but not the candidate groups.

task.setAssignee(userId);

We’ll have an application where the group is determined based on a external authentication system and we can’t set the candidate groups via a dmn or a variable inside the bpm.

The UserTask interface has methods to set the groups, but I also couldn’t find a way to get a UserTask with an Id via the Java API or update a UserTask with the TaskService.
What would be the best way to achive this?

Thanks.

Hi @jhartmann,

Yes, you can set candidate groups using addCandidateGroup method

taskService.addCandidateGroup(<TASK_ID>, <GROUP_ID>);

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.13/org/camunda/bpm/engine/TaskService.html#addCandidateGroup-java.lang.String-java.lang.String-

Hi @hassang

thanks I really missed that method.