title: Google App script on form submit trigger - delay
body: <p>I have a script set up to send out an email on receiving data from a form into a spreadsheet.  However, the auto email generates from the spreadsheet, which takes a few seconds to update the fields - so if I use the onformsubmit trigger, the content of the auto email wrongly refers to the previous submission.</p>
  
  <p>Is there a way to delay the auto email by a few seconds, giving the spreadsheet time to generate the right information before spitting out the email?</p>
  
  <p>Any help appreciated!</p>
  
  <p>Nick </p>
  
  <p>Here is the code so far:</p>
  
  <pre><code>    function EmailFormConfirmation() { 
        var ss = SpreadsheetApp.getActiveSpreadsheet(); 
        var sheet = ss.getSheetByName("Form responses");
        var email = sheet.getRange(2,9,1,1).getValue();  
        var message = "&lt;HTML&gt;&lt;BODY&gt;"
           + "&lt;P &gt;Hi " 
           + sheet.getRange(4,9,1,1).getValue()
           + ","
           + "&lt;P&gt;You have received a new request, from &lt;b&gt;"
           + sheet.getRange(5,9,1,1).getValue()
           + "&lt;/b&gt;.  "
           + sheet.getRange(8,9,1,1).getValue()
           + " asks:&lt;i&gt;"
           + "&lt;br /&gt;&lt;br /&gt;"
           + sheet.getRange(6,9,1,1).getValue()      
           + "&lt;/i&gt;&lt;P&gt;You can find your request on the log at number &lt;b&gt;"
           + sheet.getRange(10,9,1,1).getValue()
           + "&lt;/b&gt;.  
           + "&lt;br /&gt;&lt;br /&gt;"
           + sheet.getRange(8,9,1,1).getValue()
           + "'s email address is:"
           + "&lt;br /&gt;&lt;br /&gt;"
           + sheet.getRange(9,9,1,1).getValue()   
           + "&lt;/HTML&gt;&lt;/BODY&gt;";
          MailApp.sendEmail(email, "LMI Request", "", {htmlBody: message});   
      }
  </code></pre>