Global name 'shared' is not defined

Good morning,

Ignition V7.9.10

We have a global shared script used for calculating uptime on our production lines. This was migrated to another plant (gateway) and we are seeing the error below. If the function is called from a window it works fine. When the same function is called from a Value Changed tag event inside a UDT then the following error is shown in the tag diagnostics window.

image

This same script package was deployed to two other gateways with the same version and we do not have this issue. I read in an earlier post this was a bug in ignitionIs this still an open issue or is my problem a new one?

Thank you,

Tim

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 16, in valueChanged NameError: global name 'shared' is not defined

at org.python.core.Py.NameError(Py.java:260)

at org.python.core.PyFrame.getglobal(PyFrame.java:265)

at org.python.pycode._pyx14.valueChanged$1(:18)

at org.python.pycode._pyx14.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:165)

at org.python.core.PyBaseCode.call(PyBaseCode.java:301)

at org.python.core.PyFunction.function___call__(PyFunction.java:376)

at org.python.core.PyFunction.__call__(PyFunction.java:371)

at org.python.core.PyFunction.__call__(PyFunction.java:361)

at org.python.core.PyFunction.__call__(PyFunction.java:356)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:649)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$FunctionInvokerImpl.run(TagScriptManager.java:493)

at com.inductiveautomation.ignition.common.sqltags.scripts.AbstractTagScript.invoke(AbstractTagScript.java:33)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$Task.invoke(TagScriptManager.java:442)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$TagScriptDispatcher.run(TagScriptManager.java:405)

at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:518)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 16, in valueChanged NameError: global name 'shared' is not defined


Have you had any resolution around this? I am now noticing a similar error when trying to call shared scripts from within a custom function of a Gateway Tag Change script.

Try adding “Import shared” above your current code

1 Like

Gateway event scripts use a legacy python scoping mode for backward compatibility. It only loads system, project, shared, etc, in the top level of the event script. If you define any function within the event script, those functions won’t inherit higher level imports, and require the corresponding import inside the function.

I strongly recommend passing your event and associated variables to a project script function. Script modules use modern scope rules.