google-sheetsgoogle-apps-scripttriggersgoogle-forms

Troubleshooting Spreadsheet Form Submit Events Google


I'm using Google Apps Script but I can't figure out how to troubleshoot the onEdit(e) method when using Spreadsheet Form Submit.

The code is pretty straight forward. Just checks a parameter in the form data and either removes it or emails someone.

function onEdit(e) {
  var namedRange = e.namedValues;
  if (namedRange.SOME_VALUE < 3.3) {
    SpreadsheetApp.getActiveSheet().deleteRow(sheet.getLastRow());
  } else {
    MailApp.sendEmail("none@none.na", "New Entry", e.values);
  }
};

Solution

  • You would need to use an installable "on form submit" trigger to fire the script, and name the function something different to onEdit (so the simple "on edit" trigger is not fired as well).

    Functions fired by an installable trigger allow writing to the log using Logger.log() (for example, you could invoke Logger.log(namedRange.SOME_VALUE) and observe the log later). As an aside, even if there was a simple trigger available for "on form submit", I don't believe Logger.log actually works for such functions.