Hi all,Activiti version: 5.8Is there a way to assign an user task when the creation event is intercepted ?What I want to do is when a task is created, I would like to assign it to an user.I'm using the interface TaskListener to intercept the create event. In the notify method, I'm trying to set assignee but the task does not exist yet in database. Then there is a ProcessEngineException which has sens.Here is the code:
public final class TacheSuspendueTaskListener implements TaskListener {
@Autowired
private UtilisateurRepositoryService utilisateurRepositoryService;
@Autowired
private MoteurProcessusService moteurProcessusService;
@Autowired
private TaskService activitiTaskService;
@Override
public void notify(DelegateTask delegateTask) {
String lastAssignee = (String) delegateTask.getVariable("lastAssignee");
if (lastAssignee != null) {
List<Utilisateur> utilisateur = utilisateurRepositoryService.findByIdList(Lists.newArrayList(Long.valueOf(lastAssignee)));
try {
activitiTaskService.setAssignee(delegateTask.getId(), utilisateur.iterator().next().getId());
} catch (ActivitiException ae) {
throw new ProcessEngineException("Unable to assign task with taskId={} to user with userId={}.", ae,
delegateTask.getId(), utilisateur.iterator().next().getId());
}
}
}
}
My 1st question is that am I wrong using the TaskListener to achieve what I want to do ?2nd question, if I'm wrong is there another way to achieve this without using the TaskListener ?Thanks for advices.