- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2019 12:32 PM
How can Script Includes variables be called by other functions?
I have a Script Includes with several functions. Many of the data sources share a similar data source. Many of the functions generate some of the same variables. To avoid duplicating the scripting code required to populate the common variables, I want to write the script once and call that result as needed.
How?
For example,
function1
var A = lines of script to generate the "A" variable
var B = lines of script to generate the "B" variable
var C = lines of script to generate the "C" variable
var X = lines of script to generate
function2
var A = lines of script to generate the "A" variable
var B = lines of script to generate the "B" variable
var C = lines of script to generate the "C" variable
var Y = many lines of script to generate ""
function3
var A = lines of script to generate the "A" variable
var B = lines of script to generate the "B" variable
var C = lines of script to generate the "C" variable
var Z = many lines of script to generate ""
Because variables A, B, and C each require many lines and generate the same output from the same input for each function, I would like to write the code once and call the common variables as needed.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2019 01:05 PM
In the initialize secition of the script include define your variables A,B,C, but have them generated right then with private functions in the include.
this.A = this.generateA();
this.B = this.generateB();
generateaA = function () {
//do stuff to make A;
//return results;
};
generateaB = function () {
//do stuff to make B;
//return results;
};
otherFunction = function(){
//do stuff using this.A or this.B
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2019 10:06 AM
Do I need to create a series of individual generate functions after the initialize?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2019 09:31 AM
in a script include, to use an output from another method in the same script include:
getMyData: function(parm1, parm2){
var rv = '';
//do something to get the value of rv
rv = 'test_value';
return rv;
}
function1: function(source){
use some or all of the initialized variables from another method in the script includes
var x = this.getMyData();
//now you can use x
}
function2: function(source){
var y = this.getMyData();
}
********************************************
if your function needs to return more than one value you can return
an array, a comma separated string (if string), json

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2019 10:09 AM
I am thinking you need to add a "private" function to your script include. the private function would do the data manipulation for your variables. Your existing functions would then call the private function as needed.
Here is a good article on the topic Calling a script include function inside it's script include