Content of api.global survives between executions of both 1st and 2nd pass (i.e. dirty pass). But given that the second pass is a whole new JST, the global variables are persisted between the 2 passes, where the persistence is done in JSON.
So if you have a complex object (such as a 'Filter') and you store it in a global variable, the following applies:
-
Such variable can be retrieved from the global cache as a 'Filter' object only as long as you are in the first pass.
-
During the second pass, if you retrieve it, you will get the JSON representation of this object. Accessing the key of a map stored as a global variable in the second pass is done using the syntax:
Groovyapi.global.variable.map[(key)]
-
Between elements within execution of a logic.
-
Between executions of a logic for a set of items (i.e. PG, PL, ...) if
api.retainGlobal = trueis called.
This 'retainGlobal' also works for making use of global variables during executions of both 1st and 2nd pass (i.e. dirty pass).