cancel
Showing results for 
Search instead for 
Did you mean: 

how to update a process variable?

wenweikun
Champ in-the-making
Champ in-the-making
Maybe this question sounds very silly, but I can not find a solution and answer about it.

I user a process variable through the whole process instance.
So my question is can I change the process variable without compete a task?

Below is my sample code:

P1: I user this to get and view my process variable:

ProcessVariable p = (ProcessVariable) runtimeService.getVariable(
               processInstance.getId(), "processVariable");


P2: then I want to update the process variable:
ProcessVariable  is businessprocess Scope, and injected to my class.

processVariable.setStatus("Readed");


after that, I use P1 again to view the process variable
but nothing change to the process variable.

the debug result is, after P2, the injected process variable value have change, but the getVariable result of P1 remain the same..
3 REPLIES 3

trademak
Star Contributor
Star Contributor
You have to explicitly invoke the runtimeService setVariable method to update that variable.

Best regards,

wenweikun
Champ in-the-making
Champ in-the-making
Thank you so much!

BTW, can I set auto commit  for this update?

jbarrez
Star Contributor
Star Contributor
Why would you want that? It would screw the transaction going on at tat time