Setting process variable at run time

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 08:42 AM
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
- Labels:
-
Archive

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 07:40 AM
If you use service task you can set the process variables there.
<code>
public void execute(DelegateExecution execution) throws Exception {
execution.setVariable("<VariableName>",<VariableValue>);
}
</code>
You can set them similarly in script task also.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 07:47 AM
Thanks for the idea. Will try it
Thanks
Niyas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 07:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 07:49 AM
I tried this way as option # 2 mentioned in my original post. But unfortunately its not working . Values supplied as part of task completion is not carried over to the exclusive gateway for its conditional navigation.
Thanks
Niyas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 08:10 AM
What do yo mean? Those two option do that, they set the variables.
How did you verify that the variables were not set?
A small bit of test code would to understand what's happening here.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 09:02 AM
PFA the test code and the bpmn xml files for your review
Thanks
Niyas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 02:00 AM
The same process and test code is working when i use "sub process" instead of "call activity" . But ideally we will need to separate the business processes into different bpmn files . Please advise why the stuff that works with sub process is not working with call activity. Variable scope constraints ?.
Any solution to make it work with call activity ? .
Thanks
Niyas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 05:48 AM
> The same process and test code is working when i use "sub process" instead of "call activity"
Call activity _do not_ inherit variables like subprocesses.
You need to explicitly map variables in and out for call activities (checks the docs on call activity)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 07:01 AM
Thanks for the update.
Yes , i have mapped the variables in call activity. ( sourceExpression="${action}" target="action" ) .
Issue i am facing using call activity is , the value for the variable is reaching the X-OR gateway only when i declare them as part of process instance creation. (setting through run time service or task completion is not working) .
But , i could do it through a service / script task .I am still wondering why the below methods are not working with call activity as it would have made the execution simple without service / script tasks elements
1. runtimeService.setVariable(processInstance.getId(),"variable","value");
2. taskService.complete(tasks.get(0).getId(), vars);
Thanks
Niyas
