Button onClick event NameError when calling script from script library

I have a global script library setup. I can call the scripts from it fine in tag change events and SFC from other projects. I am using the onClick Script action for a Perspective button, but when I try to call a script from the Script Library Project named NH-ScriptLibrary, I get an error.

Error running action 'dom.onClick' on P70X RD AUTO@D/root/Button: Traceback (most recent call last): File "<function:runAction>", line 35, in runAction NameError: global name 'plexAPI' is not defined

The code is

	response = plexAPI.setJob(checkJob, workcenterKey)

plexAPI is the name of the script in the Project NH-ScriptLibrary that is set as the Gateway Scripting Project.

I tried using the Project name, but the get "NameError: global name 'NH' is not defined".

I could be wrong, but it seems like in this scope it does not like the '-' in the project name. Or I am just missing something obvious.

Thanks,

Jon

I would assume the - is not a valid character for a package name as it is a reserved character in python.

The error is likely being generated by the NH being interpreted as a variable name in some sort of subtraction operation.

I would switch the hypen out for an underscore in the package name and try it out.

The gateway scripting project setting is not relevant when you're using a script from anywhere associated with a particular project (which is basically everywhere except for a tag). In that case, you're going to get your local project's script library (including any parent project(s)). You cannot reference library scripts in another project; you can only use those that are part of your inheritance tree.

Thus, it's usually a good idea for shared logic to have a "base" project that purely defines library scripts and truly global things, and inherit from that in all your other projects.

1 Like

Thanks. I will have to reconfigure some things.

I would be nice to be able to have all my scripts in one place and just have others use them. They are wanting to have the scripts and the API keys in a project that is protected and only certain people can modify or view. But would like for others to be able to use the scripts.

Thanks,

This is not possible. You can apply some guardrails to projects, but any person with any designer access to a gateway can use scripting to access everything in the gateway, including everything the gateway can reach in the filesystem.

If an untrusted individual needs to work on a project, you must use a separate dev gateway where the secrets are not present. (Presumably, a different set of test credentials would be present.) The work product would need to be deployed to the sensitive server by a trusted individual.

There is no alternative. (No, the new secrets management in v8.3 won't fix this case.)

1 Like