0

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---

2 Answers2

1

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;}

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • where do I use it. – Abdullah Salma Jul 28 '21 at 06:37
  • in the onFormSubmit function that is triggered by the form submission. – Cooper Jul 28 '21 at 11:30
  • The reality of this sort of thing is that you will have to study the problem and determine if it's possible to identify unwanted triggers. If not then you'll just have to wait for a fix. I suspect that most programmers don't use Google Forms so they don't ever have this problem. I know I never use google forms so perhaps you can circumvent the problem by rolling you own forms via html, css and javascript thus avoiding the problem altogether. – Cooper Jul 28 '21 at 11:54
0

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

Andres Duarte
  • 3,166
  • 1
  • 7
  • 14