This article will be useful to those who need to change or modify their Apps Script code (including the code posted on this site) to their immediate needs.
And the first question:
Of course, in order for the code to work again, it needs to be debugged.
And first of all, we need to find a place after which problems begin and the code behaves in a completely different way from what is expected of it.
There may be several strategies here. The most reliable of them (but not the fastest) is to check the entire code step by step, starting from the very beginning.
To do this, in the editor window, you must:
In this figure, the program stopped just at the breakpoint on the 32nd line.
In the same figure, you can see that in the right block under the heading Debugger there are four buttons:
Below the control buttons of the Debugger block is the Variables block, which shows the current value of the variables at each program breakpoint.
In addition, we can print the desired values to the console using the command:
console.log(variable)
These data are displayed on the images in the lower part in the Execution log block.
If we want to test the operation of a function that has arguments (for example, the function fillColumn(row, col, mask)), then the best solution is to first create a helper function tmp(), where
Then, the launch of this very auxiliary function tmp() for debugging, in fact, will be the launch of the fillColumn function itself with arguments.
In fact, in the figure above, the tmp() function plays a similar auxiliary role for the fillColumn(row, col, mask) function.
The onEdit(e) system function is used to intercept data changes/entry on Google spreadsheet and does not respond to the standard breakpoint processing by the debugger. Therefore, we will not be able to debug it in the usual way.
There are at least two solutions:
Browser.msgBox(variable);
For the convenience of debugging the second scenario, you can add the values of any variables as arguments to variable.
Now, to run the second option, you need to make any changes to the Google spreadsheet. This will immediately run the onEdit(e) function. And if there are no errors before the message box launch line, then we will definitely see a window with the variable.
For more information on how to debug scripts in the Apps Script editor, you can get from this video (RU voice):