onFormSubmit trigger activates multiple times

1,132 views
Skip to first unread message

Angdi Chu

unread,
Jun 8, 2019, 3:21:44 AM6/8/19
to Google Apps Script Community

I linked a form's results to a spreadsheet, and use onFormSubmit trigger to do a function whenever the form has a new fill in. It has been running for 2 weeks. However, when I looked at Stackdriver logging yesterday, I found out that it has been a problem for a couple days. Every time there was a new record, the trigger was activated 2~3 times these days. 

Is it the trigger's glitch? Is there anything I can do to solve it? Thanks.

Alan Wells

unread,
Jun 8, 2019, 7:58:21 AM6/8/19
to Google Apps Script Community
Google "On Form Submit" triggers have a long history of failing.  People are constantly complaining of duplicate instances of code running from a trigger, and triggers silently failing.  This has been going on for years.  Google engineers have failed to fix problem.  Apps Script bugs can take years to fix.
There are legitimate reasons for triggers running twice that is caused by the programmer, like if you are using a "simple" trigger, and also "install" a trigger to the same name.  That happens frequently.  But there is no simple trigger for "On Form Submit" triggers.  So, it can't be that.

I think it may be possible to programmatically install a trigger to the same function name multiple times.  You should check the current projects triggers by opening the script, and from the "Edit" menu choose "Current Projects Triggers"

Triggers other than time-based triggers should to be "scoped" to the Apps Script file that installed them. So, if you had multiple Apps Script files, all with the same function name associated with the same type of trigger, then there shouldn't be a conflict.  But as I stated, something is going wrong somewhere with triggers.  Each trigger should have it's own unique ID, which is probably how Google determines what trigger goes with what Apps Script project file.

Is there any chance that your code is somehow installing the trigger multiple times to the same function name?

Alan Wells

unread,
Jun 8, 2019, 8:04:43 AM6/8/19
to Google Apps Script Community
Here is a StackOverflow post of a situation that fixed an On Form Submit problem in a spreadsheet.

Angdi Chu

unread,
Jun 8, 2019, 8:29:23 AM6/8/19
to Google Apps Script Community
Thank you!

I've checked my triggers, and there is only one trigger in this script. 

I was going to add a lock to prevent that happened again, but now I'm going to add this conditional statement too. Thanks so much!

David Gentile

unread,
Jun 9, 2019, 6:07:48 AM6/9/19
to Google Apps Script Community
I'll add that this is an issue I've dealt with before on a Google Form that was emailing results to respondents. For some reason it would run multiple times, resulting in multiple emails sent to the respondent.

To fix I had the code check a column labelled "Email sent" which the code inserted a timestamp. If it wasn't blank (meaning the code had already run) it would not continue and thus prevented any further emails being sent. Not ideal but a workaround that had proven to work. Hope the underlying issue is addressed at some stage.
Reply all
Reply to author
Forward
0 new messages