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?
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?
Hi,
The following snippet demonstrates how you can get the information about task candidates:
@Component(TaskCreatedNotificationSender.NAME)
public class TaskCreatedNotificationSender {
public static final String NAME = "my_TaskCreatedNotificationSender";
@Inject
private UserGroupService userGroupService;
@Inject
private DataManager dataManager;
private static final Logger log = LoggerFactory.getLogger(TaskCreatedNotificationSender.class);
@EventListener
protected void onTaskCreated(UserTaskCreatedEvent event) {
TaskData taskData = event.getTaskData();
TaskService taskService = ProcessEngines.getDefaultProcessEngine().getTaskService();
//get the Flowable task object
Task task = taskService.createTaskQuery()
.taskId(taskData.getId())
.singleResult();
//get candidate group codes from identity links
List<? extends IdentityLinkInfo> identityLinks = task.getIdentityLinks();
String groupId = identityLinks.get(0).getGroupId();
log.info("Candidate group code: {}", groupId);
UserGroup userGroup = dataManager.load(UserGroup.class)
.query("where e.code = :code")
.parameter("code", groupId)
.one();
//find users of the given user group using the UserGroupService
List<User> users = userGroupService.getUsers(userGroup);
String userLogins = users.stream()
.map(User::getLogin)
.collect(Collectors.joining(", "));
log.info("Group users: {}", userLogins);
}
}
Perfect, thanks