cancel
Showing results for 
Search instead for 
Did you mean: 

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

maudrid
Champ on-the-rise
Champ on-the-rise
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 log.info 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);
   log.info("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();
   log.info("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.
4 REPLIES 4

maudrid
Champ on-the-rise
Champ on-the-rise
In case there is confusion about why the log says 'SCMBulkUpload.js', it should say 'myTestLog'. I renamed it when preparing this post but did not run it again to get new log output.

Also I forgot to mention that I am using Activiti 6 beta 2

maudrid
Champ on-the-rise
Champ on-the-rise
*bump*

Anyone?

maudrid
Champ on-the-rise
Champ on-the-rise
Still nothing?

ghamer
Champ in-the-making
Champ in-the-making

I also had this issue.

The issue here is that you are creating user tasks in a SubProcess but quering for tasks using the processInstanceId of the parent process. 

To fix this, first find the sub-process instance where the Tasks were created:

ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId( theSCMProcess.getInstanceId() ).singleResult();

then perform the Task search using the id of the sub-process.

Task task1 = taskService.createTaskQuery().processInstanceId( subProcessInstance.getInstanceId() ).singleResult();