AnsweredAssumed Answered

Groovy script in scriptTask, process variable scoping issue?

Question asked by jpalomaki on Aug 4, 2011
Latest reply on Sep 13, 2011 by mathiasd
Hi,

I have a Serializable Java bean object stored in process variable "application":


public class Application implements Serializable {
    private String identifier;
    // Getter + setter
}

Now if I modify this object in a groovy script using a <scriptTask /> like so:


<scriptTask id="setIdentifier" scriptFormat="groovy">
    <script>
        application.identifier = "123"
        // OR: application.setIdentifier("123")
    </script>
</scriptTask>

then the identifier is not stored to the Application object pointed to by the process variable "application".

If I do this however:


<scriptTask id="setIdentifier" scriptFormat="groovy" activiti:resultVariable="application">
    <script>
        application.identifier = "123"
        application
    </script>
</scriptTask>

then the object pointed to the by the process variable "application" is indeed updated.

So it seems that a copy of the original object is made for the duration of the script, even if I refer to the process variable directly.

Is this expected behavior?

Thanks,
Jukka

Outcomes