google script how to call library functions dynamically?
I have a set of libraries that have the same functions in each (each
library is associated with a template and every time different templates
can be used, depending on the user request). I am trying to create a code
that will call functions dynamically. This is fine as long as the
functions are in the same script. However, my functions are in different
libraries and when I try to call them I get an error: Execution failed:
TypeError: Cannot find function Script2.getItBack in object [object
Object]. (line 25, file "dynamicFunctionsTest").
Here is the code:
function test1() {
return 'raining';
}
function test2() {
return 'cats';
}
function test3() {
return ScriptLibrary1.returnWord(); // the function returns the word
'and'
}
function testing() {
var message;
var func = [];
func [0] = 'test1';
func [1] = 'test2';
func [2] = 'test3';
func [3] = 'ScriptLibrary2.returnWord'; // the function returns the
word 'dogs'
Browser.msgBox(func); // check values before calling
for (var i = 0; i < func.length ; ++i) {
message = this[func[i]](); // this line fails on the 4th
one
Browser.msgBox(message);
}
}
I am getting the first 3 working (the third was just a test to see if I
can call locally which works but is insufficient for my purpose), but it
fails on the 4th one.
Anyone has any idea how to get it to work?
Thanks.
No comments:
Post a Comment