0

I have a script to run a function when a Google Form is submitted, and a new row added to my google spreadsheet. Alas, it fails to trigger. There is no error reported and I don't receive a notification email. The function works when executed manually, and new rows are added to the spreadsheet as expected when a form is submitted.

I have installed the trigger through the resources tab, to run onFormSubmit() when theres an event on the spreadsheet. I have tried onChange and onFormSubmit, both with no response. The on edit trigger works as expected when I manually edit the spreadsheet. The simple function it should run is below.

function onFormSubmit() {
Browser.msgBox("Success")
}

Any pointers would be greatly appreciated, thanks.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Dale J
  • 1
  • 3

2 Answers2

0

I was curious about if what really happens so I just made a test.

I didn't get an error message or notification email but the Execution Transcript shows that the script was fired

[18-04-14 18:20:35:056 CDT] SpreadsheetApp.getActiveRange() [0 seconds]
[18-04-14 18:20:35:056 CDT] Range.getRow() [0 seconds]
[18-04-14 18:20:35:056 CDT] Range.getLastRow() [0 seconds]
[18-04-14 18:20:35:057 CDT] Range.getColumn() [0 seconds]
[18-04-14 18:20:35:057 CDT] Range.getLastColumn() [0 seconds]
[18-04-14 18:20:35:057 CDT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[18-04-14 18:20:35:151 CDT] Starting execution
[18-04-14 18:20:35:158 CDT] Browser.msgBox([Success]) [0 seconds]
[18-04-14 18:20:35:160 CDT] Execution succeeded [0.002 seconds total runtime]

On my test I put the spreadsheet and the form side by side. There was no dialog box shown.

The explanation is that the script instance fired by an installable trigger is not aware about if the user has open the spreadsheet or not (Browser is only available on the Google spreadsheet context).

If the point is to show an dialog to the user when a form submission is received, this require a a "poller" like the one described by on the Mogsdad's answer to How do I make a Sidebar display values from cells?

Rubén
  • 34,714
  • 9
  • 70
  • 166
-1

Looks like you can't use Browser.msgBox() with Forms.

Inside your trigger function, call Logger.log("function was called")

You'll see that the function gets called in your logs.

FormApp.getUi().alert("hello") will create a message box in the form editor, but not the live form.

AshClarke
  • 2,990
  • 5
  • 21
  • 27
  • Thanks for your response. The script is within the spreadsheet, not the form. Browser.msgBox() should create a message box within the spreadsheet, as it did when I successfully ran an onEdit() trigger. – Dale J Jul 09 '14 at 08:41
  • Thanks. The trigger wasn't calling onFormSubmit() at all. Copy/Pasting the code into a new spreadsheet fixed the problem. Strange, but it works, at least for now. – Dale J Jul 09 '14 at 11:38