Set Global Variable

Trying to set a global variable in a custom app. I can't quite figure out the correct syntax. Here is the basics of what I am doing.

def newStatus = "1"
setGlobalVar("ModeStatus", newStatus) This line errors out.

Tried:
setGlobalVar("ModeStatus", "newStatus") Still errors out.

First, are you dealing with "global variables" (from Rule Machine Legacy) or hub variables (under Settings)? This API only works with hub variables.

Your first one looks like it should work, assuming you do mean hub variables. What specific error do you get?

1 Like

It is a Hub Variable under settings. Here is the error.

app:32122022-11-12 07:57:33.690 AMerrorjava.lang.NullPointerException: Cannot get property 'valueAsString' on null object on line 64 (method installed)

Can you share a complete, minimal, non-working snippet?You may find the problem yourself by doing that, too. What you have above should work. My suspicion from your error is that newStatus isn't set to what you think it is at that point (though that obviously shouldn't be the case in what you posted above). You can try adding a line like this right before setting the variable to see:

log.debug "$newStatus"

2 Likes

Well sometimes your brain and your eyes, or at least mine, don't seem to work together. The variable name should have been modeStatus, NOT Modestatus. Dad burned capital letters...:slight_smile:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.