0

I'm building an addon for the response submissions from a Google Form, so the addon is a script on the SpreadSheet.

The addon is still unpublished because it's under development, and to further develop the script, I want to catch the onFormSubmit event, and do some stuff with the user's submitted data.

I tried adding a new trigger programmatically, but in doing so, the addon just bails, as in, the addon disappears, and doesn't reload at all, and there's no errors report by email. At one point, after adding the code for the onFormSubmit listener, from the script editor, I tried doing "Publish > test as addon...", and selected the spreadsheet to test agains, and I was asked to provide another permission to the script - and even tho this was necessary because the scripts scope had changed, I still couldn't get the addon to load.

Gahh, here's what I tried:

function onOpen(e) {
  addFormSubmissionListener();
  // other init...
}

function addFormSubmissionListener() {
  var sheet = SpreadsheetApp.getActive();
  ScriptApp.newTrigger("onFormSubmit")
     .forSpreadsheet(sheet)
     .onFormSubmit()
     .create();
}

function onFormSubmit(e) {
  // do stuff with form submission //
  Logger.log(e.response.getId());
}
2
  • Add-on doesn't send failure emails itself. You have to handle the errors. Refer this documentation for more info about installable triggers in add-ons.
    – rpm
    Feb 5, 2015 at 0:46
  • Yah, thanks, I've read all the docs, including the blurb on adding installable triggers after the script was installed. I tested the above code on a new script (new Google App Script Project), and it works, so there's some step failing in my previous script. The Google App Script platform is great in that its ubiquitous and free, but it's a nightmare to debug.
    – asking
    Feb 5, 2015 at 16:03

1 Answer 1

0

Would something like this get you ontrack.

    function onInstall() {
  addFormSubmissionListener();
  // other init...
}

function addFormSubmissionListener() {
  var sheet = SpreadsheetApp.getActive();
  ScriptApp.newTrigger("onFormSubmit")
     .forSpreadsheet(sheet)
     .onFormSubmit()
     .create();
}

function onFormSubmit(e) {
  // do stuff with form submission //
  Logger.log(e.values);
}

The onInstall() should mean the trigger only gets installed the once and the install only run once. You may wish to also check the current projects triggers before installing it as a trigger, incase it is there already.

When I submit a form. I'm getting the form values logged in logger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.