AnsweredAssumed Answered

Complete task and get next tasks. Transactions and query sync.

Question asked by emptyfruit on Apr 27, 2016
Latest reply on May 13, 2016 by emptyfruit
Hi. I'm using Activiti 5.19
In my code on "logically" completing a task i have some logic of saving data from the form (ui). At the end of the method i call a "task complete" method and then query for all the tasks i have availible next for current user (1 or more). The lines go next to each other:


processEngine.getTaskService().complete(taskId);

List<Task> tasks = processEngine.getTaskService().createTaskQuery()
                .processVariableValueEquals(WfConst.ROOT_EXECUTION_ID, rootExecutionId)
                .active()
                .taskCandidateUser(username)       
                .list();


The issue is that the taskQuery executes faster than
complete(taskId)
method. So result list is not full. Especially this happens when the UserTask ends with a CallActivity (creating a subprocess). So i never get the first task that belongs to this subprocess. But if i wait for some time (1-5 sec) in debugger and query again - the task is there and the list if full. Sometimes the query happens so early, that it is simply empty. What are my options on performing these two actions in one transaction?

Outcomes