# System function calls not recognized from Timer Script Function

**URL:** <https://forum.inductiveautomation.com/t/system-function-calls-not-recognized-from-timer-script-function/67301>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [December 6, 2022, 4:55pm UTC](https://forum.inductiveautomation.com/t/system-function-calls-not-recognized-from-timer-script-function/67301 "2022-12-06T16:55:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zack.beranek](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zack.beranek/32/29953_2.png) [@zack.beranek](https://forum.inductiveautomation.com/u/zack.beranek)\
**Post date:** [December 6, 2022, 4:55pm UTC](https://forum.inductiveautomation.com/t/system-function-calls-not-recognized-from-timer-script-function/67301/1 "2022-12-06T16:55:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 6, 2022, 5:07pm UTC](https://forum.inductiveautomation.com/t/system-function-calls-not-recognized-from-timer-script-function/67301/2 "2022-12-06T17:07:42Z")

</div>

This is due to some very long standing scoping issues.

> [@Global Variables are not recognized in functions in "Gateway Events Scripts"](https://forum.inductiveautomation.com/t/global-variables-are-not-recognized-in-functions-in-gateway-events-scripts/31856/2):
>
> This is not really a bug, but it is annoying. Gateway event scripts use legacy python scope rules that prevent any names in the top level event scope from being captured in nested functions’ closures. (Ignition v8 would have been a good choice to drop the backward compatibility…) If you find you need to define a nested function within a gateway event script, you probably should move the whole thing to a project script module. Then your gateway event becomes a one-liner, something like so: […

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

---

<div class="post-metadata">

**Author:** ![zack.beranek](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zack.beranek/32/29953_2.png) [@zack.beranek](https://forum.inductiveautomation.com/u/zack.beranek)\
**Post date:** [December 6, 2022, 6:24pm UTC](https://forum.inductiveautomation.com/t/system-function-calls-not-recognized-from-timer-script-function/67301/3 "2022-12-06T18:24:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 6, 2022, 6:54pm UTC](https://forum.inductiveautomation.com/t/system-function-calls-not-recognized-from-timer-script-function/67301/4 "2022-12-06T18:54:45Z")

</div>

> [@zack.beranek](#):
>
> 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.
