cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script in scriptTask, process variable scoping issue?

jpalomaki
Champ in-the-making
Champ in-the-making
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
3 REPLIES 3

jpalomaki
Champ in-the-making
Champ in-the-making
Oh and just for the record, this also works:


<scriptTask id="setIdentifier" scriptFormat="groovy">
    <script>
        def local = application
        local.identifier = "123"
        application = local
    </script>
</scriptTask>

Regards,
Jukka

jbarrez
Star Contributor
Star Contributor
mmm, it must be something groovy specific then, because the engine doesnt do any copies.

mathiasd
Champ in-the-making
Champ in-the-making
I'm encoutering the same problem with a javascript task : http://forums.activiti.org/en/viewtopic.php?f=6&t=2394
I think the problem is that the object is updated only if there is an affectation (with the sign = ) in the script.