I would recommend that you use a Task Listener instead of an Execution Listener for this purpose. In Camunda Modeler, you’ll see the ability to add a Task Listener immediately under the box that will let you add an Execution Listener. (Task Listeners can only be added for User Tasks.)
A Task Listener class should implement the TaskListener interface, which simply requires that the class implement the notify(DelegateTask task) method. The DelegateTask Object will then give you access to the following methods which will be of interest to you:
getAssignee() -> Retrieves the assignee for the User Task if one has been specified (which would be the case if the User Task has been claimed).
getCandidates() -> Retrieves a java.util.Set of IdentityLink Objects, which can hold either candidate groups or candidate users.
Here’s a quick and dirty implementation of the notify(DelegateTask task) method that can be set to run on “create” and “assign” and that will print the assignee or the candidates - if no assignee exists - to the console:
@Override
public void notify(DelegateTask task) {
if(task.getAssignee() != null) {
String assignee = task.getAssignee();
log.info("The assignee for task " + task.getId() + " is: " + assignee);
}
else {
log.info("Task " + task.getId() + " is not yet assigned. Displaying all candidate users and groups...");
Set<IdentityLink> identityLinks = task.getCandidates();
if(identityLinks.isEmpty())
log.info("No candidate users or groups exist for this User Task. Id: " + task.getId());
else {
for (IdentityLink identityLink : identityLinks) {
if(identityLink.getGroupId() != null)
log.info("Task " + task.getId() + " has an identity link for a group with id: "
+ identityLink.getGroupId());
else if(identityLink.getUserId() != null)
log.info("Task " + task.getId() + " has an identity link for a user with id: "
+ identityLink.getUserId());
}
}
}
}
Note that you can also use a script - e.g. using JavaScript - as a Task Listener as well. In that case, you’ll have access to the same task Object.