AnsweredAssumed Answered

Force serialization after a Script Task

Question asked by mathiasd on Sep 13, 2011
Latest reply on Sep 13, 2011 by mathiasd
Hi,
I would like to manipulate some objects (Java Objects) in script task. For example :


<scriptTask id="scripttask1" name="Setter" scriptFormat="javascript">
      <script><![CDATA[
               object1.setValue(1);
          ]]></script>
    </scriptTask>

The java code which starts a process instance is :

Map<String, Object> variables = new HashMap<String, Object>();
variables.put("object1", new MyObject());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(name,businessKey,variables);

The problem is that the engine doesn't serialize object1 at the end of the script task, because the engine doesn't know that the object1 has changed. I would like to know if there is a way to notify the engine "object1 has changed !" ?

The solution I found is to change the set method in order to return the object. So the script is :


<scriptTask id="scripttask1" name="Setter" scriptFormat="javascript">
      <script><![CDATA[
               object1 = object1.setValue(1);
          ]]></script>
    </scriptTask>

Is there another solution ?
Actually the list of manipulated objects is well-known, so a "hard-coded" solution like "save the object1 after each script task" would be good enough.

Outcomes