Script runs twice on google form submit trigger

Related searches

I'm create Google form and google app script with sendFormByEmail function, also I set on form submit trigger for this function, my issue is this script run two time on form submit and I'm getting two email, I want only single email on form submit. my script code is below.

var no_repeat=0;
function sendFormByEmail(e){

  var email = "test@XXXXDXtest.com"; 

  var s = SpreadsheetApp.getActiveSheet();
  var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];    
  var message = "";
  var subject = "Success Assessment";
  var total=0;
  var roll_on=0;

  message+="test massage";
  message+="<table cellpadding='3' style='color: #0F1F4C;'>";
  for(var i in headers) { 
    if(headers[i]=='Please enter your email address to receive your results'){
      email=e.namedValues[headers[i]].toString();
    }
    if(headers[i]!='Please enter your email address to receive your results'){
      if(headers[i]!='Timestamp'){
        if(e.namedValues[headers[i]]!=''){      
          total = parseInt(e.namedValues[headers[i]])+parseInt(total);
        }

        message +="<tr >";
        message += '<td >'+headers[i]+'</td><td >'+e.namedValues[headers[i]].toString()+ "</td>";
        message +="</tr>";
        roll_on++;
      }
    }
  }  
  message +="<tr >";
  message += "<td ><b> YOUR SCORE </b></td><td ><b>"+total+"</b></td>";
  message+="</tr></table>";

  // Send the email

   if(email!='' && email!=null){
     if(no_repeat==0){ 
       MailApp.sendEmail(email, subject,"",{htmlBody: message});
     }
    no_repeat++; 
   }
}

This is a known issue at Google's end and they are working on a fix:

Our engineering team is working on the issue, but we don't have any estimates as to when it will be fixed. I advise applying the LockService logic as shown in update #22, which should work around the problem.

Resetting Triggers in Google Apps Script, December 1, 2017 | Posted in Google Apps Script attached to a spreadsheet or document, the triggers that run those scripts can sometimes start to malfunction. If that's the case, where you want to listen for a form submission and then take� Script executions and API requests do not cause triggers to run. For example, calling FormResponse.submit () to submit a new form response does not cause the form's submit trigger to run.

I had same issue. The problem was that two users set up the same on submit trigger on the Google Form. I signed in as one of the users and deleted the trigger. I signed in as the other user and the trigger was still there. Works perfectly now, only runs once.

Google form uploaded file is saved twice in my Drive, I have a script running on form submit (with a trigger) which renames the file before saving it, tho only the one in Form_Name (File Responses)� I'm currently trying to make a paperwork wizard using google forms and apps script. At the end of the form, I'm trying to run an Apps Script once the form submits and display a HTML window.

I've had the same issue on my spreadsheet, apparently it's a glitch the developers are trying to solve.

I have a similar spreadsheet that runs fine, however it was developed before the last update on the page that manage triggers.

Anyway, as a work around, I've created an extra column on my spreadsheet to ensure the script only runs once for each line, adding two code lines, the first to setvalue to the new column with 'OK' and an if to check that column

Hope it helps!

Att.

Class FormTriggerBuilder | Apps Script, Like simple triggers, installable triggers let Apps Script run a function An installable form submit trigger runs when a user responds to a form. The Form “On Submit” event is used to run a script when the Google Form is submitted. An “On Form Submit” trigger can be added to either a Form, or a Spreadsheet or both. An “Event Object” is

Looks like this still hasn't been fixed by the GAS team yet.

After spending weeks trying to get to the bottom of random glitches occurring in our script, we finally found this post. Very frustrating!

We found a simple variable check onSubmit to be an effective workaround:

function handleSubmit() {
    if (window.formSubmitted !== undefined) {
        return false;
    }
    window.formSubmitted = true;
    console.log("Should never fire twice!");

    google.script.run...
}

Installable Triggers | Apps Script, Assuming that the Script editor window is still open, A summary of the new trigger will be shown to you immediately. You'll notice that there's a Last run timestamp since we just sent a new submission to test the trigger. Google Forms and Google Sheets to allow your� Learn to Magically Send Emails from your Google Form Responses. click the little ‘stopwatc h’ icon to set up a trigger so that this runs automatically. If I run this script (with a new

Allow users to update your app's data with Google Forms , Triggers let Apps Script run a function automatically when a certain event, like opening a document, occurs. Simple triggers are a set of reserved functions built into Apps Script, like the function onOpen(e), which executes when a user opens a Google Docs, Sheets, Slides, or Forms file.

Trigger: Creates and returns the new trigger. onFormSubmit() FormTriggerBuilder: Specifies a trigger that will fire when a response is submitted to the form. onOpen() FormTriggerBuilder: Specifies a trigger that will fire when the form's edit view is opened.

Simple triggers and installable triggers let Apps Script run a function automatically if a certain event occurs. When a trigger fires, Apps Script passes the function an event object as an argument, typically called e. The event object contains information about the context that caused the trigger to fire.

Comments
  • hi, amit I'm already gothrouth it befor posting my Questions here, and "lock.waitLock" not working for me I tried it as per solution #22: code.google.com/p/google-apps-script-issues/issues/…
  • Was delighted to see an update, but this does not appear to be Apps Script code, but rather for a .html file