I'm trying to shorten the path of a tag through a script, and then calling the script from an expression tag alarm template. The value I get is always null when I pass in {PathToTag}, yet if I pass in the full path in as a string then I get the correct value returned. Any ideas as to what I'm doing wrong? I've already configured the Gateway Scripting for my project.
You should really be passing in your args via the runScript args, e.g.
runScript('ShortenTagPath.ShortenPath', 0, {PathToTag})
However to pass them in as you are, you need to use:
runScript('ShortenTagPath.ShortenPath("' + {PathToTag} + '")', 0)
Some other things:
- Unless you're just testing, you should really think more about your structure and naming of your script libraries. You shouldn't have a single function in each of your script libraries which is how it appears you're using them. They should hold collections of like-functions for similar purposes. Use IA's
system
library as a good example. - library and variable names shouldn't use PascalCase. They should use camelCase (or snake_case)
- You should also never use Python keywords as variables names (e.g.
list
- notice the golden highlighting) - instead of a for loop and constant reassignments, you can use:
string = '/'.join(lst)
Here's a link to the Python style guide: PEP 8 – Style Guide for Python Code | peps.python.org
Note that while snake_case is preferred for Python, Jython is rooted in Java which uses camelCase so many people prefer this. camelCase is also used throughout the system
library so using this would make custom functions more consistent across the application.
3 Likes