AnsweredAssumed Answered

Make start process variables accessible inside of ExecutionListener?

Question asked by cold_gin on Jan 15, 2014
Latest reply on Jan 16, 2014 by frederikheremans1
Is it possible to access the variables map that is passed into runtimeProcess.startProcessInstanceByKey('processKey', variables) ** inside of an ExecutionListener **? I want to set a particular variable that will change with each process execution programmatically, but it seems as though these variables are not persisted yet when the executionlistener is kicked off. So the sequence I want to achieve is:


1.)

// Start process programmatically:

variables.put("my_var_key", "my Value");

ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processKey, businessKey, variables);



2.)

// Now the executionlistener will execute, but the variable that I added to the variables map is not available:

public void notify(DelegateExecution execution) throws Exception {



execution.getEngineServices().getRuntimeService().hasVariable(execution.getId(), "my_var_key");   // It returns false…

}


I have also tried to set the variable via runtimeService after calling startProcessInstanceByKey, but the variable is still not available (it's either too late, or the DB transaction has not been committed yet).

My specific needs are not to set variables inside of the execution listener. The key thing here is that I need to be able to associate process ID with some data that I am passing into the process on start, and I need that association to be present inside of the process execution listener for the functionality that I need to implement… Also, I do not want to add any special variables into the workflows themselves. I want to be able to do this all programmatically outside of the scope of XML so that I can implement my functionality regardless of the workflow definition.

Can some type of process initialization map attribute be added to the DelegateExecution object so that the arguments passed into the startProcessInstanceByKey method can be made accessible to the execution listener? With all of the posts that I have read in this forum on this subject, it seems like there are quite a number of people who would like to be able to do exactly what I am describing.

Thanks

Outcomes