cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with setting process variable on a usertask listener

marcthomas2012
Champ in-the-making
Champ in-the-making
Hi,

I have a workflow whose first task has a listener attached to it. This listener performs some processing and then attempts to store the result in the activiti process variable. This doesn't work for me because I always get the exception

SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: execution 5 doesn't exist
   at org.activiti.engine.impl.persistence.entity.TaskEntity.fireEvent(TaskEntity.java:529)

Whilst debugging through the code I see that the process is started using processInstanceId = workflowManager.startWorkflow(processDefinitionKey, processBean); and the task listener is invoked before the startWorkflow method returns. I can only assume that the execution hasn't fully been setup by the time the user task listener is invoked and therefore the execution ID it is trying to use to save the process variable doesn't completely exist.

The code works fine if the same listener, configured in the same way is attached to a second task.

Any ideas? Does this sound like a defect with Activiti or am I doing something wrong?

The events that I tried to attach the listener to are create and also assignment. Neither work for me.

Thanks
Marc
4 REPLIES 4

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Do you have the (minimalized) code of your listener?

marcthomas2012
Champ in-the-making
Champ in-the-making
Hi,

I have created a unit test in an eclipse project to demonstrate the issue and shared it via dropbox as I couldn't upload it to the forum. (https://www.dropbox.com/s/c144xoxd637oerl/Development.zip)

There is a method call verifyTestVariableValueCorrect which I am expecting to pass for both calls made to it. However, an exception is thrown in the listener which is attached to both tasks in the process.

I'd really appreciate any help that you can provide.

Thanks
Marc

jbarrez
Star Contributor
Star Contributor
Don't use the runtime service from inside listener, rather use the following:

delegateTask.getExecution().setVariable("", "");

marcthomas2012
Champ in-the-making
Champ in-the-making
Fantastic, thank you for the help.

Marc