Unable to acces task list from DelegateExecution.getEngineServices()
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2014 09:33 AM
Hello everyone.
I have a serviceTask with a java class which launches a class
The class itself implements JavaDelegate like this
It gives me an empty task list. It seems that the processId I get is not the "real" processInstanceId.
So I cannot get the TaskService, runtimeService, etc.
Thank very much you if you see a solution.
I have a serviceTask with a java class which launches a class
<serviceTask id="Initialisation" name="Initialisation" activiti:class="acoss.activiti.DelegateInitialisation"></serviceTask>
The class itself implements JavaDelegate like this
public class DelegateInitialisation implements JavaDelegate { @Override public void execute(DelegateExecution de) throws Exception { String processId = de.getProcessInstanceId(); TaskService tkService = de.getEngineServices().getTaskService(); List<Task> ltasks = tkService.createTaskQuery().processInstanceId(processId).list(); for (Task task : ltasks) { System.out.println(task.getId()); } }}
It gives me an empty task list. It seems that the processId I get is not the "real" processInstanceId.
So I cannot get the TaskService, runtimeService, etc.
Thank very much you if you see a solution.
Labels:
- Labels:
-
Archive
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2014 05:26 AM
The processId is the "real" process instance id.
The task query returns user tasks that are not yet completed in the process instance. Do you have any open user tasks in your case? It will not include service tasks.
Best regards,
The task query returns user tasks that are not yet completed in the process instance. Do you have any open user tasks in your case? It will not include service tasks.
Best regards,
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2014 05:44 AM
Thank you very much for this fast answer.
In fact it's not only a matter of tasks. It seems that the engineService instance is not available in the JavaDelegate context.
If I code
<code>
public void execute(DelegateExecution exec) throws Exception
{
String processId = exec.getProcessInstanceId();
RuntimeService rtService = es.getRuntimeService();
ProcessInstance pi = rtService.createProcessInstanceQuery().processInstanceId(processId).includeProcessVariables().singleResult();
}
</code>
There's no exception at execution but the pi processInstance is null.
Certainly I make a mistake somewhere, but the Activiti Java architecture is very complex, so it's easy if you're not experienced to get astray.
In fact it's not only a matter of tasks. It seems that the engineService instance is not available in the JavaDelegate context.
If I code
<code>
public void execute(DelegateExecution exec) throws Exception
{
String processId = exec.getProcessInstanceId();
RuntimeService rtService = es.getRuntimeService();
ProcessInstance pi = rtService.createProcessInstanceQuery().processInstanceId(processId).includeProcessVariables().singleResult();
}
</code>
There's no exception at execution but the pi processInstance is null.
Certainly I make a mistake somewhere, but the Activiti Java architecture is very complex, so it's easy if you're not experienced to get astray.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2014 05:47 AM
Sorry M. Rademakers I've forgot something, the code is :
<code>
public void execute(DelegateExecution exec) throws Exception
{
String processId = exec.getProcessInstanceId();
EngineServices es = exec.getEngineServices();
RuntimeService rtService = es.getRuntimeService();
ProcessInstance pi = rtService.createProcessInstanceQuery().processInstanceId(processId).includeProcessVariables().singleResult();
}
</code>
<code>
public void execute(DelegateExecution exec) throws Exception
{
String processId = exec.getProcessInstanceId();
EngineServices es = exec.getEngineServices();
RuntimeService rtService = es.getRuntimeService();
ProcessInstance pi = rtService.createProcessInstanceQuery().processInstanceId(processId).includeProcessVariables().singleResult();
}
</code>
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2014 08:13 AM
Do you have a unit test demonstrating this?
The process instance id should not be null there.
However, is this service task executed when the process is started? If so, the process instance won't be flushed to the database and the query will return no results.
The process instance id should not be null there.
However, is this service task executed when the process is started? If so, the process instance won't be flushed to the database and the query will return no results.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2014 08:35 AM
Yes this process is executed from the beginning, since there's no userTask beetwen it and startEvent.
I've managed to use an other way for solving my problem, so close this topic.
Thank you for trying to solve this issue.
I've managed to use an other way for solving my problem, so close this topic.
Thank you for trying to solve this issue.