cancel
Showing results for 
Search instead for 
Did you mean: 

Make start process variables accessible inside of ExecutionListener?

cold_gin
Champ in-the-making
Champ in-the-making
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
2 REPLIES 2

cold_gin
Champ in-the-making
Champ in-the-making
Sorry my bad. The wrong method was being called in the code where the workflow was being started. Adding a variable to the map does indeed allow the data to pass through to the ExecutionListener, and I can get to the variable now by calling execution.getEngineServices().getRuntimeService().getVariables(execution.getId()) in the ExecutionListener.

Sorry again for the false alarm.

frederikherema1
Star Contributor
Star Contributor
Even better to use the DelegateExecution method passed in, to get the variables. This is 100% guaranteed to be the current state of the execution…