Menasheh
Menasheh

Reputation: 3708

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?

Upvotes: 11

Views: 15760

Answers (1)

Serge insas
Serge insas

Reputation: 46792

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;
}

Upvotes: 10

Related Questions