Global variables and Callbacks

How do you achieve global variables in Groovy. I have looked at some examples on line but cannot get them to work. In a nut shell I have a sendHubCommand that has a callback associated with it. What I would like is to update some global variable and then use that data in another method. I have tried using

@Field String array = new String[10]

def callback(…)
array = {…}
log( array )

def anotherMethod()

In the above example the log outputs the value the populated array from the callback method. However, when being output in ‘anotherMethod’ it is always empty. I have tried loads of different combinations but to the same avail.

How can I achieve this.



Use state.array = […] in callback() and then you can access it from anotherMethod()

state is a global object of type map

Take a look at Edge Drivers! They run locally and allow automations to run the same way (depending on the Automation config)

There are different samples than can help you get started: