System function calls not recognized from Timer Script Function

Ignition Version 8.1.19

Can anyone tell me if I am missing a fundamental rule about using Gateway Timer Scripts that would prevent me from calling a system function from within another function?

For example:
In a Gateway Timer Script, I can execute the following without issue:
now = system.date.now()

However, if I put that code inside a function and then call it like this:
def GetNow():
return system.date.now()

GetNow()

I get the following error message in the logs:
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 4, in File "", line 2, in GetNow NameError: global name 'system' is not defined

Obviously this code is for example and serves no real purpose, but this is the case for any system function I try to call from within my function. Thanks in advance for any insight.

1 Like

This is due to some very long standing scoping issues.

Place your code in a function in a script module and then call that script from the Gateway Event.

4 Likes

Thank you @lrose! I was afraid it was something like that.

Honestly, I would generally recommend using a project script for gateway events anyway, even if legacy scoping wasn't an issue.

1 Like