com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 3, in onScheduledEvent UnboundLocalError: local variable 'system' referenced before assignment
at org.python.core.Py.UnboundLocalError(Py.java:295)
at org.python.core.PyFrame.getlocal(PyFrame.java:240)
at org.python.pycode._pyx60209.onScheduledEvent$1(:16)
at org.python.pycode._pyx60209.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyBaseCode.call(PyBaseCode.java:308)
at org.python.core.PyFunction.function___call__(PyFunction.java:471)
at org.python.core.PyFunction.__call__(PyFunction.java:466)
at org.python.core.PyFunction.__call__(PyFunction.java:461)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:842)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:824)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:681)
at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:993)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:746)
at com.inductiveautomation.ignition.common.script.ScheduledScriptManager$ScheduledScriptTask.run(ScheduledScriptManager.java:148)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 3, in onScheduledEvent UnboundLocalError: local variable 'system' referenced before assignment
... 21 common frames omitted
how to declare line 3 in scheduled script? Please help me out @PGriffith
Do you actually need import system in that script? It is a new-style script instead of an event-style, so I wouldnât expect it to have this legacy scope problem.
This problem seems to be related to the Scheduled event. My script doesnât run using the Scheduled event, but it runs without error using the Timer event. Wrapper.log shows the Scheduled event error is UnboundLocalError: local variable âsystemâ referenced before assignment. The first line is:
You shouldnât need to import system in order to use the system functions within Scheduled Scripts. Iâve been unable to reproduce a situation where it errors, even if you do include it (both on 8.1.7 and 8.1.12).
It does look like if you try to place an import system within an if block like the original post it does indeed produce that error⌠Just remove that line altogether, you shouldnât need it.
Anything that starts with system.* e.g. system.db.runPrepQuery had legacy scope intricacies in versions prior to 8, depending on where the code was running.