Calling a user-defined function from different meta data point scripts
-
Infinite Automation states "You can use the Global Scripts module to call a custom function from each meta data point." How exactly is this done?
The Scripting Data Source wiki page states:
Global scripts are automatically included in the script execution, such that functions and variables defined there are available. Note that if global scripts are changed, the scripting data source must be restarted to reload them.
So I defined a function in a "Scripting data source" script window, validated it (confirmed by "Script completed successfully"), and then enabled the data source. However, I could not call the function from a meta data source:
Script error: sun.org.mozilla.javascript.EcmaError: ReferenceError: "mySpecialFunction" is not defined. (#2) in at line number 2 in at line number 2
What is the difference between a "Scripting data source" and a "Global Script?" How does one define a "Global Script?" What is the exact meta data point syntax required to call the function?
Thanks for your help.
-
@Pedro The Global Scripts module is a separate icon on the main menu:
You can not define a global script in a scripting data source but you can call a global script from a scripting data source or meta data point.
Let me know if that clears it up?
-
Thanks, that clears it up: I thought with the Mango Enterprise download I had all the m2m2 modules, but apparently I must not, as it does not appear on my datasource list. I suppose I must download it separately.
-
This module is not a data source. It appears on the main menu along with the sql console and other modules.
-
I guess I confused them. Thanks.
-
I could only find "Global Scripts" under the "Meta Data Source" and "Scripting Data Source" wiki headings. Consequently, it is unclear which of the "Scripting Data Source" recommendations also apply to global scripts (and also why I did not think to look at the icon bar for the Global Scripts). Specifically, the Scripting Data Source states:
Note how the typeof function is used to determine if constants need to be defined. This is an effective way of initializing the script context upon startup of the data source.
if (typeof(rho) == "undefined") { rho = 28; sigma = 10; beta = 8/3; dt = 0.01; }
I have defined functions containing equations in Global Scripts. They contain implicit constant definitions. For example:
return (2.43941E-7*W3 -0.5433*W2 +0.06*W+2.0)
The function seems to be working fine, but I'm concerned about the "effective way" cited on the Scripting Data Source page. Should I pull those constants out of the equation and declare them within a typeof structure? What are the implications of not doing that? Performance? Memory? Memory leaks? Why is this recommended for a Scripting Data Source? Speed?
Thanks.