cancel
Showing results for 
Search instead for 
Did you mean: 

link newTask to process instance

ajeje93
Confirmed Champ
Confirmed Champ

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.

1 ACCEPTED ANSWER

I haven't tried to create a new execution for now. So i cannot answer your question.

Yeah there is an option to change the process definition dynamically. The two following links can help for this approach.

Design by Doing 1

Design by Doing 2

But i have another question. Would it be enough to create subtasks? These can be queried in the history. 

View answer in original post

10 REPLIES 10

Design by doing it's the correct solution.

I'm sorry if I didn't let you know if it worked, but I never had the chance to try it until now.