Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  47] [ 4]  / answers: 1 / hits: 15265  / 10 Years ago, fri, july 25, 2014, 12:00:00

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?


More From » debugging

 Answers
6

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

[#70039] Wednesday, July 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylanalis

Total Points: 438
Total Questions: 85
Total Answers: 102

Location: Barbados
Member since Sun, Nov 27, 2022
1 Year ago
;