Either global or universal variables would work in theory, but there are a couple of points to consider in practice:
If you use globals, you’ll need to run the script that defines the variables at the beginning of each run of scripts. If you run a set of scripts from the scheduler, each script will need to run the constant setup script if it is to have access to your constant definitions. And you won’t be able to do a run selection on a portion of the script that requires those constants to be defined.
If you use universal variables, you’ll only need to run the script that defines them once in each Eggplant session; scripts run from the scheduler will be able to access the constants once they have been defined without each script having to run the setup script; and you will be able to do run a selection that refers to those constants. The downside is that you wouldn’t be able to test whether a value was set (shouldn’t be doing that with a constant anyway) and you may get so used to having them defined that you forget to run the setup script when you need to (as when running from the command line).
One way of handling the defining of the scripts is to set up a file that defines a property list, like so:
If you make a mistake in formatting your data file, the value function will throw an error, but it won’t tell you specifically where the problem is. Then, assuming you saved this file as “~/Eggplant/constantDefs.txt”, you could have a setup script with the following line:
put the value of file "~/Eggplant/constantDefs.txt" into universal CONST
and you could reference your constants like this:
-- make sure to declare this universal variable
-- in each script that needs to access your constants
SendMail( to: CONST.EmailAddress, subject:"hi", body:"I'm Eggplant.")
put file CONST.SuiteHome & "MySuite/Scripts/MyScript.script" into aScript
In this way you’ll have all of your constants defined in a central location, making them easy to update and add to.
Thanks for the interesting question. Please let us know if this isn’t clear or there is anything else that we can help you with.