Is there any way to debug a Spreadsheet google app script at runtime? Just running it through the script editor is not useful, because the function I need to debug takes the trigger event as an argument.
Asked
Active
Viewed 4,465 times
1
-
On what trigger does it run ? The best you can do is to simulate the function with data that might occur on the trigger – Srik Sep 11 '12 at 16:23
-
It runs on a form submit trigger, for a spreadsheet attached to it. The event data is the entry in the spreadsheet, but simulating the data might not be the best way to debug it since I might be overlooking the real error. – sanketalekar Sep 11 '12 at 16:56
3 Answers
2
Here is a function that can test form submission trigger functions, lifted from How can I test a trigger function in GAS?.
function test_onFormSubmit() {
var dataRange = SpreadsheetApp.getActiveSheet().getDataRange()
var data = dataRange.getValues();
var headers = data[0];
// Start at row 1, skipping headers in row 0
for (var row=1; row < data.length; row++) {
var e = {};
e.values = data[row];
e.range = dataRange.offset(row,0,1,data[0].length);
e.namedValues = {};
// Loop through headers to create namedValues object
for (var col=0; col<headers.length; col++) {
e.namedValues[headers[col]] = e.values[col];
}
// Pass the simulated event to onFormSubmit
onFormSubmit(e);
}
}
1
The simple answer is no - you can't debug on a form submit. You can however, write Logger.log statements in your onSubmit code and then write the log contents to say another spreadsheet or sheet which you can take a look later on.

Srik
- 7,907
- 2
- 20
- 29
-
1Can you give some example code as to how to write the log contents to another spreadsheet? – TechplexEngineer Jun 24 '13 at 19:28
-
Try the library at http://stevewhisenhant.wordpress.com/2013/03/25/google-apps-script-logging-library/ – Srik Jun 25 '13 at 05:52
1
Not sure what your question about, but try this.
function get_color(e) {
//var data = e.parameter.nameLabel
var data = red;
if (data == red){
//...
} else {
//...
}
}
so you can use the debugger to test your scripts without considering events
I hope it helps you!