How to get list of user emails from a groupid?

Currently i am able to get group id by:
Set candidates = delegateTask.getCandidates();
Iterator iterator = candidates.iterator();
while (iterator.hasNext()) {
System.out.println("Task ID: ";

From there, how can get list of users in that group and their Email ID’s(Through Java Code)


Got solution, Thanks!

@kirankk what was the answer?

@StephenOTT Thanks for you interest

        String taskId = delegateTask.getId();
	IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();

	ArrayList<String> groupIDs = new ArrayList<String>();

	for (IdentityLink link : delegateTask.getCandidates()) {
		LOGGER.log(Level.INFO, "Group iDs: " + link.getGroupId());

	if (!groupIDs.isEmpty()) {

		// create user list by querying via group ID
		for (String groupID : groupIDs) {

			List<User> userList = identityService.createUserQuery().memberOfGroup(groupID).list();

			// mail to each user in the group
			for (User userInGroup : userList) {

				String assignee = userInGroup.getId();
				String recipient = userInGroup.getEmail();

				if (recipient != null && !recipient.isEmpty()) {

					Email email = new SimpleEmail();
					email.setAuthentication(USER, PWD);

					try {
						email.setSubject("Task assigned: " + delegateTask.getName());
						email.setMsg("Please complete: http://localhost:12306/camunda/app/tasklist/default/#/task/"
								+ taskId);


						email.send();"Task Assignment Email successfully sent to user '" + assignee
								+ "' with address '" + recipient + "'.");

					} catch (Exception e) {
						LOGGER.log(Level.WARNING, "Could not send email to assignee", e);

				} else {
					LOGGER.warning("Not sending email to user " + assignee + "', user has no email address.");



1 Like

@kirankk, how did you get ‘delegateTask’ ?

Hey liang,

When you create a Java TaskListener class you have to Override the notify function. This function has as an input the DelegateTask.
But remember: You got to have a user task in your bpmn, to have a TaskListener. An ExecutionListener has a DelegateExecution as an input variable in the notify function.

Hope this helps.
Kind regards,