Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a spreadsheet custom function in google script?

I am writing a custom function to be used in a spreadsheet and I would like to be able to at least display some data. Few things seem to work, for example Browser.msgBox doesn't find the appropriate permissions.

Breakpoints don't interrupt execution.

I had some hope for this code

function test() {
  var s = "test"
  Logger.log(s)
  return s + s
}

But when I set a cell in the spreadsheet to "=test()" the cell properly shows the value "testtest" but when I return to the script editor and use view>execution transcript or view>logs I don't see anything.

Perhaps this logging goes to a special file somewhere?

like image 211
WesR Avatar asked Nov 03 '22 19:11

WesR


1 Answers

When you use a custom function as a formula, it can be evaluated and re-evaluated at many times. Therefore, it is not appropriate to fill up the Logging output or the Execution Transcript with this. If you want to debug, you must run (or debug) the script manually from the script editor.

Take an example, where you have two custom functions - f1() and f2() And say, in cell A1, you enter the formula =f1() and in A2, you enter =f2(A1). In such a case, both the cells will be re-evaluated. So what should the logger output show ?

like image 197
Srik Avatar answered Nov 08 '22 15:11

Srik