Auto complete user task in task listener

In my user task listener, I will check some conditions, if conditions be evaluated to true, I need to finish this task with varaibles in this listener without user action, but I find delegate task has no api to complete itself. What should I do to complete task?

I would recommend to do not create a task in such a case. (e.g. exclusive gateway)

Regards
Martin

List<TaskEntity> taskEntities = CommandContextUtil.getTaskService().findTasksByExecutionId(delegateTask.getExecutionId());
Optional<TaskEntity> t = taskEntities.stream().filter(taskEntity -> taskEntity.getId().equals(delegateTask.getId())).findFirst();
TaskHelper.completeTask(task, inpustVars, null, null, null, CommandContextUtil.getCommandContext());

Now I use code above to finish the task, is it ok?

User task listener listens to user task events (created…) Wy do you need to “autocomplete” a task right after the task is created?
Martin

User task is one of my review flow, same reviewer may appears in review flow several times, if reviewer approve in the first review task, it should auto complete the following task that assigned to this reviewer. I also need to record all the review tasks, so every review task should be created in flow.

Too complicated, good candidate for refactoring.

1 Like