Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you pass an argument to the Google Apps Script debugger?

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?

like image 493
Menasheh Avatar asked Jul 25 '14 12:07

Menasheh


1 Answers

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;
}
like image 136
Serge insas Avatar answered Sep 23 '22 18:09

Serge insas