AnsweredAssumed Answered

Null result from taskService.createTaskQuery().processInstanceId().singleResult() in a script task

Question asked by maudrid on Sep 30, 2016
Latest reply on Jul 13, 2018 by ghamer
I'm having a problem with taskService.createTaskQuery().processInstanceId().singleResult() when executed in a script task.
I have tried the same code in a unit test and it works correctly. To me it looks like the query is not selecting data in the same session.
Like data that is not yet committed is not available to it.

Here is my scenario.

I have 2 processes:
1. This process starts the second process and completes one of the user tasks of the second process.
2. This process is started by the first process and has a few users tasks, but no branching.

Process 2
This process and a start node user task 1, user task 2 and an end node.
I have added a listener on task 1 for debugging. lit just does a to see if it is created.

Process 1
This consists of a start node, script task and end node.
In the script task the following code is giving me a problem, but the same code works if I place it in a unit test.

   var Logger = Java.type('org.slf4j.LoggerFactory');
   var log = Logger.getLogger('myTestLog');
   var HashMap = Java.type('java.util.HashMap');
   var variables = new HashMap();
   variables.put('test1, '1');
   variables.put('test2, '2');
   var theSCMProcess = runtimeService.startProcessInstanceByKey("SCM", variables);"Process: " + theSCMProcess.getId()); // This is returning a process id

   // get the first user task that was generated
   var task1 = taskService.createTaskQuery().processInstanceId(theSCMProcess.getId()).singleResult();"Task: " + task1); // This is returning null

Here is the log output:

2016-09-30 10:19:14,762 INFO  [Task1Listener.js] Task "Task 1" (380190) created.
2016-09-30 10:19:14,974 INFO  [SCMBulkUpload.js] Process: 380177
2016-09-30 10:19:14,998 INFO  [SCMBulkUpload.js] Task: null

Any idea how I can get this to work?
I have stepped through the code when executing on the server side up to selectList() in org.apache.ibatis.session.defaults.DefaultSqlSession.
The query executes but there are no results. After the the script is finished I can see the newly created process and task exists.