Reputation: 1
I have about 10 Google Scripts that send emails out when a form is submitted. It was working fine until recently, but suddenly all of them have started sending out two emails for any form submit. I've looked at the Execution Log and there are always 3 seconds between the first and second execution (the scripts only take about 1.5 seconds each to run).
I tried using a script lock (a solution I found on here) but so far, have not been able to stop the duplicate emails. I'm not sure if I did it correctly.
SpreadsheetApp.flush();
var lock = LockService.getScriptLock();
try {
lock.waitLock(500);
} catch (e) {
Logger.log('Could not obtain lock after 30 seconds.');
}
function sendEmails() {
---rest of the code---
Upvotes: 0
Views: 206
Reputation: 3340
Your problem is caused to a recently reported Google bug about on form submit triggers being run twice: https://b.corp.google.com/issues/144110219
Upvotes: 0
Reputation: 64082
My experience is that the unwanted or as I call them spurious submissions tend to be missing some of the answers. So I looked at the spurious submissions carefully to determine if there are any difference between the first and following spurious submissions and I often found that the spurious submissions always just contain the timestamp. So as I said in this answer I use the following code to exclude the spurious submission from effecting my onSubmitForm functions: if(e.values && !e.values[1]){return;}
Upvotes: 1