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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2016 07:06 AM
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: 3801772016-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.
- Labels:
-
Archive

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2016 07:23 AM
Also I forgot to mention that I am using Activiti 6 beta 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2016 09:38 AM
Anyone?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2016 09:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 11:04 AM
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();
