1

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.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
sanketalekar
  • 119
  • 1
  • 3
  • 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 Answers3

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);
  }
}
Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
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
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!

Mike Aski
  • 9,180
  • 4
  • 46
  • 63
tolkedu
  • 61
  • 1
  • 9