cancel
Showing results for 
Search instead for 
Did you mean: 

Setting process variable at run time

niyas_m
Champ in-the-making
Champ in-the-making
Hi,

  I am new  to Activiti . I would like to know how to set process variables to an existing process instance ( already instantiated ) at run time. The use case to provide condition value for an exclusive gateway following an user task completion .

I tried the following methods .

1. runtimeService.setVariable(processInstance.getId(),"variable","value");

2. Upon completing the task prior to the exclusive gateway
 
      taskService.complete(tasks.get(0).getId(), vars);

  (The conditional value for the gateway will be known only at this point in time , ie task completion, not prior to process instantiation)

Both are not working .

The only thing working is when i pass process variables as part of process instantiation.

How to accomplish this ? Any working examples / workarounds ?

Please help

Thanks
Niyas
11 REPLIES 11

jbarrez
Star Contributor
Star Contributor
Okay, I looked at your test.
The reason is because a call activity _is_ actually a real process instance (it will show up in queries as such).
Hence, when you set your variable

  runtimeService.setVariable(pi.getId(), "action", "task2");

You're setting it on the main process, not on the new started process.
Add the following line and it will work:

ProcessInstance newProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
runtimeService.setVariable(newProcessInstance.getId(), "action", "task2");

niyas_m
Champ in-the-making
Champ in-the-making
Hi Barrez,

  Thanks for the solution. Will try as suggested

Regards
Niyas