How to involve task candidate groups automatically when the task is created in Alfresco Process Services

To add a candidate group as a participant of a task, you can do it easily thanks to the task listeners.

1. Add a task listener to your user task.
2. Set the task listener as ScriptTaskListener
3. Add the following code to the script section of the task listener:

def execution = task.getExecution();
def taskService = execution.getEngineServices().getTaskService();
List identityLinkList = taskService.getIdentityLinksForTask(task.getId());
 
for (int i = 0; i < identityLinkList.size(); i++) {
  def oneLink = identityLinkList.get(i);
  
  if (oneLink.getType() == "candidate" && oneLink.getGroupId() != null) {
    taskService.addGroupIdentityLink(task.getId(), oneLink.getGroupId(), "participant");
  }
}

Notes: keep semicolons at the end of the lines to avoid issues, because APS might wrap all the code into one line.