AnsweredAssumed Answered

link newTask to process instance

Question asked by ajeje93 on Feb 8, 2017
Latest reply on Feb 21, 2017 by ajeje93

I'm trying to modify Activiti 5.22 source code in order to link a task, created with the method newTask from the class TaskService, to a process instance, so that when I'm calling historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).finished().orderByHistoricActivityInstanceEndTime().asc().list() the list contains also the task that I added during execution.

In some way I managed to do that modifying the class NewTaskCmd in this way:

public class NewTaskCmd implements Command<Task>, Serializable {

 

    private static final long serialVersionUID = 1L;

 

    protected String taskId;
    protected String processInstanceId;
    protected String processDefinitionId;
    protected String executionId;

 

    public NewTaskCmd(String taskId, String processInstanceId, String processDefinitionId) {
        this.taskId = taskId;
        this.processInstanceId = processInstanceId;
        this.processDefinitionId = processDefinitionId;
        this.executionId = processInstanceId;
    }

 

    public Task execute(CommandContext commandContext) {
        Date currentTime = commandContext.getProcessEngineConfiguration().getClock().getCurrentTime();
        TaskEntity task = TaskEntity.create(currentTime);
        task.setId(taskId);
        task.setProcessInstanceId(processInstanceId);
        task.setProcessDefinitionId(processDefinitionId);
        task.setExecutionId(processInstanceId);
        return task;
    }

 

}

 

If I set the executionId in that way the following exception is throwed calling the complete method on any of the task of the process, even the ones included in the process definition:

ERROR org.activiti.engine.impl.interceptor.CommandContext  - Error while closing command context org.activiti.engine.ActivitiException: UserTask should not be signalled before complete

 

Although, if I do not set the executionId the history service query will not contain the new task that I created.

What am I doing wrong? How can I avoid the signal error?

Thanks in advance to everyone that will answer.

Outcomes