cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to acces task list from DelegateExecution.getEngineServices()

cnirparis
Champ in-the-making
Champ in-the-making
Hello everyone.

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.


      
5 REPLIES 5

trademak
Star Contributor
Star Contributor
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,

cnirparis
Champ in-the-making
Champ in-the-making
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.

cnirparis
Champ in-the-making
Champ in-the-making
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>

jbarrez
Star Contributor
Star Contributor
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.

cnirparis
Champ in-the-making
Champ in-the-making
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.