Get Candidate Groups of Task

Hi there,

On Task creation, I want to send emails to the Task’s Candidate Group’s Users.
Is it possible to get the Candidate Groups / Users in a UserTaskCreatedEvent Listener for the given task?

The following snippet demonstrates how you can get the information about task candidates:

public class TaskCreatedNotificationSender {

    public static final String NAME = "my_TaskCreatedNotificationSender";

    private UserGroupService userGroupService;

    private DataManager dataManager;

    private static final Logger log = LoggerFactory.getLogger(TaskCreatedNotificationSender.class);

    protected void onTaskCreated(UserTaskCreatedEvent event) {
        TaskData taskData = event.getTaskData();
        TaskService taskService = ProcessEngines.getDefaultProcessEngine().getTaskService();
        //get the Flowable task object
        Task task = taskService.createTaskQuery()
        //get candidate group codes from identity links
        List<? extends IdentityLinkInfo> identityLinks = task.getIdentityLinks();
        String groupId = identityLinks.get(0).getGroupId();"Candidate group code: {}", groupId);

        UserGroup userGroup = dataManager.load(UserGroup.class)
                .query("where e.code = :code")
                .parameter("code", groupId)
        //find users of the given user group using the UserGroupService
        List<User> users = userGroupService.getUsers(userGroup);

        String userLogins =
                .collect(Collectors.joining(", "));"Group users: {}", userLogins);

Perfect, thanks