[Question]How to use Project Scripts

Vision issue here. I have imported a large project and there are things complaining about “NameError: global name ‘project’ is not defined”

Essentially calling project scripts with “project.myFuncs.callMe(‘Hello World’)” is not working. I just did the tutorial found in the help and it works in 7.9.9 but not in 8.0.0-beta0 (b2019031402)
https://docs.inductiveautomation.com/display/DOC80/Project+and+Shared+Scripts

I apologize in advance if this is in the forum, I did search around for a while.

Did you change anything or just an unmodified backup restore?

Can you upload/send your backup to us?

You no longer reference “project” scripts with project.package_name.method_name any longer, unless your “Scripting/Project Library/<package_name>” is actually “Scripting/Project Library/project”
In the following screenshot I would reference THIS project’s scripts with project.Security.<method_name>
56%20PM
And I would access shared scripts (which are located in the parent project) with shared.<package_name>.<method_name>

Notes:

  • Inherited scripts are always under “shared” regardless of the parent project’s name.
  • “project” only happens to be what I’ve named the package - you can name it anything else (within reason) and reference it with <high_level_package_name>.<low-level_package_name>.<method_name>(**args)

OK so simply put: remove the “project.” and it works! Or… move the scripts into a folder called “project”
Thanks.

Yes, but...

Was this an unmodified upgrade that just stopped working or were you trying to reference project scripts that don't exist in a new project?

It was a big existing project, legacy screens that couldn’t find the scripts any more. Restored by import export not a gateway backup upgrade.

It sounds like these are new scripts.

Well its both, lots of screens exported from 7.9.9 had the error then I went to v8.0 help and it instructed me to use “project.script.sub” so updating the documentation is really the answer. (Yes i understand the documentation is underway)

I’m working on replicating this, but I need some clarifications:
Did you import a 7.9.9 project, OR did you upgrade an already deployed 7.9.9 project, OR did you restore a 7.9.9 Gateway backup?

jhottell - cmallonee is asking these questions because doing an update of an existing system with the installer or restoring a .gwbk from a prior version into 8 is supposed to automatically put scripts in the right location so they don’t have any issues. In theory, if you do an upgrade, you shouldn’t need to change any of your scripts and everything should continue to work as it did before.

OK sorry for the delay.
It is NOT from gateway or project backup. Its from FIle --> Import and Export.
I just tried it again and they all imported into the same space which may be intentional?

There are some other reasons why restoring from a gateway backup doesn’t work on my system so I can’t test how that would work (UDT’s referencing themselves as a parent type) but that is another story.

Thanks

Hi. We have recently upgraded a server from 7.9 to 8 and are seeing a similar issue with referencing the inherited shared scripts. We have several tag event scripts that are calling out a legacy script with the syntax listed above. In one example of ours looks like “shared.OEE.logdowntime()”, but we’re still seeing the error that the global name ‘shared’ is not defined.

The project “global” has the scripts from the upgrade and is inheritable and set as the parent project to the project using these tags, but I’m not certain tag event scripts are tied to any project settings. Please let me know if there is a different syntax or solution for letting tags reference the new project and legacy scripts. Thank you.

Can you check that the “Gateway Scripting Project” setting is pointing at the “global” project?

https://docs.inductiveautomation.com/display/DOC80/Gateway+Settings

1 Like

Also, have you restarted the gateway since restoring? There’s an issue (fixed in 8.0.10) with the initial gateway launch after restoring from 7.9 not correctly ‘setting’ the gateway scripting project (although it does update the setting, so subsequent restarts are fine).

Hi yes I saw this setting in the gateway and it was correct. I selected save changes and immediately saw some of our global scripts store data into SQL so it seems a refresh was needed. We also had a refresh issue with setting our default tag provider where it was set correctly and we happened to press the refresh button and saw the issues go away.

I have not restarted the server since installing so I will do so now thank you! I will reply here if we see the issue return otherwise I think it just needs to refresh it’s settings after they’ve been updated thanks for your help!

A post was split to a new topic: Problems restarting gateway