Persisting modified variables in scriptTask
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2013 11:37 AM
Hello,
I start a process with an output variable which is a basic HashMap. In a javascript scriptTask, I insert some values into this map as follows:
If I read the process variables inside an ExecutionListener at the end of the process, the result value is as expected :
However, the modified variable is not persisted in the DB, a HistoricVariableInstance query returns the variable state at the beginning of the process. To have the variable persisted, I have to force it manually:
Is it the intended behavior ? Do I have to manually persist all variables modifications ?
Regards,
Tom
I start a process with an output variable which is a basic HashMap. In a javascript scriptTask, I insert some values into this map as follows:
output.put("result", "success");
If I read the process variables inside an ExecutionListener at the end of the process, the result value is as expected :
public void notify(DelegateExecution execution) throws Exception { String result = ((Map) execution.getVariable("output")).get("result"); // success
However, the modified variable is not persisted in the DB, a HistoricVariableInstance query returns the variable state at the beginning of the process. To have the variable persisted, I have to force it manually:
output.put("result", "success");execution.setVariable("output", output);
Is it the intended behavior ? Do I have to manually persist all variables modifications ?
Regards,
Tom
Labels:
- Labels:
-
Archive
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2013 01:20 PM
Are you aware of the autoStoreVariables attribute (described here http://www.activiti.org/userguide/index.html#bpmnScriptTask) ?
You have to explicitly set the value to true if you want to persist values automatically in a script task.
Best regards,
You have to explicitly set the value to true if you want to persist values automatically in a script task.
Best regards,
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2013 09:12 AM
Hi Tijs,
Thanks for your answer. Yes I had tested with this attribute and found out that it works only for variables defined in the script. In my script, the variable in already defined prior to scriptTask execution. With this attribute, modifications are persisted only if I do:
<code>
<scriptTask id="success" activiti:autoStoreVariables="true" scriptFormat="javascript">
output.put("result", "success");
output = output;
</code>
Could it be that modifications should be detected and are not ? Please let me know if you would like a testcase to exhibit this behaviour.
Regards,
Tom
Thanks for your answer. Yes I had tested with this attribute and found out that it works only for variables defined in the script. In my script, the variable in already defined prior to scriptTask execution. With this attribute, modifications are persisted only if I do:
<code>
<scriptTask id="success" activiti:autoStoreVariables="true" scriptFormat="javascript">
output.put("result", "success");
output = output;
</code>
Could it be that modifications should be detected and are not ? Please let me know if you would like a testcase to exhibit this behaviour.
Regards,
Tom

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2013 05:12 AM
Hi Tom,
Good point, I think Activiti isn't able to see the changes to the HashMap. For now I guess we have to go for the explicit call.
Yes, you can create a JIRA for this with a test showing the issue.
Best regards,
Good point, I think Activiti isn't able to see the changes to the HashMap. For now I guess we have to go for the explicit call.
Yes, you can create a JIRA for this with a test showing the issue.
Best regards,
