Say I have the following broken example function in a google-apps script. The function is intended to be called from a google sheet with a string argument:
function myFunction(input) {
var caps = input.toUpperCase()
var output = caps.substrin(1, 4)
return output
}
While this example script should break on line 3 when you select myFunction and press debug, as there is no such method as "substrin()," it will break on line 2, because you can't put undefined in all caps:
TypeError: Cannot call method "toUpperCase" of undefined. (line 2, file "Code")
Question: Is there an official way to pass a string to a google-apps script for testing/debugging without making an additional function
function myOtherFunction() {
myFunction("testString")
}
and debugging that?
The function as you wrote it does need a parameter and there is no way to avoid that except by including a default value in the function itself. See example below
function myFunction(input) {
input= input||'test';
var caps = input.toUpperCase();
var output = caps.substrin(1, 4);
return output;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With