1

I have an Google form that field crews fill out and submit. The attached javascript emails the contents of the form as emails to everyone in the office.

The execution times are super long. One has 19496 reported seconds, when Gsuite should automatically terminate any script at 5 minutes. Some have "Unknown" status in the Google app script execution log and 0 seconds.

Is the Gsuite quota being used up? Is there an error in my script?

The user running the script trigger also receives a bounce back email, even through all the emails are going through, and the Google sheet is receiving the response from the Google Form normally.

I tried adding "if(e.values && !e.values[1]){return;}" to the top and "return;" at the bottom. It didn't seem to change the issue.

I edited the google app script below to remove the real list of the email addresses, and shortened up the report. The purpose of the Google Form is to provide a real summary of their days work instead of just "Job is done" in an email. So, they fill out a list of 15 questions instead.

function myFunction(e){

// Set values for event "e" from Response form, each number being a column in the spreadsheet 
    var value1 = e.values[1];
    var value2 = e.values[2];
    var value3 = e.values[3];
    var value4 = e.values[4];
    var value5 = e.values[5];


  // Build subject and message for email that will be sent out
    var subject1 = value5 + " Job #" + value2 + " " + value3 + " Job Report Submitted " + value1 + "    -oOo-";
        var message_html = "<b>Date:</b> " + value1 + "<br>" + 
                   "<b>Job Number:</b> " + value2 + "<br>" +
                     "<b>Site Name:</b> " + value3 + "<br>" +
                     "<b>Client:</b> " + value4 + "<br>" +
                       "<b>Crew Chief:</b> " + value5 + "<br>";            


     // Send email to chief, of what the chief submitted through the Response form
     var chiefemail = "leo@email.com"; //setting leo email as the default - but this should not be used based on below 
     var chiefname  = "Leo E.";

     if (value5 == "Bryan N.") {
                                    chiefemail = "bryan@email.com";
                                    chiefname  = "Brian N";}
     else if (value5 == "Carl B.") {
                                    chiefemail = "carl@email.com";
                                    chiefname = "Carl B";
                                   }
     else if (value5 == "Clay W.") {
                                    chiefemail = "clay@email.com";
                                    chiefname = "Clay W";
                                     }
     else if (value5 == "Dakota P."){
                                    chiefemail = "dakota@email.com";
                                    chiefname = "Dakota P";
                                     }



 // Send emails to all office staff:     

   var EmailList = "brian@email.com," + chiefemail; 


       MailApp.sendEmail({
                          to: EmailList,
                          subject: subject1,
                          htmlBody: message_html,
                          name: chiefname,
                          replyTo: chiefemail
                           });


}

I want the script to terminate, and I don't want to receive bounce back emails. Help!

Rubén
  • 34,714
  • 9
  • 70
  • 166
Scot May
  • 121
  • 10
  • The execution time limits depends on the account type. See https://developers.google.com/apps-script/guides/services/quotas – Rubén May 09 '19 at 03:14

3 Answers3

1

I think it may be possible that your experiencing what I call spurious onFormSubmit triggers and I might try something like this.

function myFunction(e){
  if(e.values && e.values[1] && e.values[2] && e.values[3] && e.values[4] && e.values[5]) {
    var value1 = e.values[1];
    var value2 = e.values[2];
    var value3 = e.values[3];
    var value4 = e.values[4];
    var value5 = e.values[5];
    var subject1 = value5 + " Job #" + value2 + " " + value3 + " Job Report Submitted " + value1 + "    -oOo-";
    var message_html = "<b>Date:</b> " + value1 + "<br>" + 
      "<b>Job Number:</b> " + value2 + "<br>" +
        "<b>Site Name:</b> " + value3 + "<br>" +
          "<b>Client:</b> " + value4 + "<br>" +
            "<b>Crew Chief:</b> " + value5 + "<br>";            
    var chiefemail = "leo@email.com"; //setting leo email as the default - but this should not be used based on below 
    var chiefname  = "Leo E.";
    if (value5 == "Bryan N.") {
      chiefemail = "bryan@email.com";
      chiefname  = "Brian N";}
    else if (value5 == "Carl B.") {
      chiefemail = "carl@email.com";
      chiefname = "Carl B";
    }
    else if (value5 == "Clay W.") {
      chiefemail = "clay@email.com";
      chiefname = "Clay W";
    }
    else if (value5 == "Dakota P."){
      chiefemail = "dakota@email.com";
      chiefname = "Dakota P";
    }
    var EmailList = "brian@email.com," + chiefemail; 
    MailApp.sendEmail({
      to: EmailList,
      subject: subject1,
      htmlBody: message_html,
      name: chiefname,
      replyTo: chiefemail
    });
  }
}

Your read more about it here. You can also check you stack driver log to see whats going on.

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • 1
    I added that, but it didn't resolve my issue. The email comes in after 1 second, but the duration in the Executions log continue to climb up and up to 55 second. Then, it changed to 0s, and Unknown status. I will try looking at the Stackdriver logs also. Thanks. – Scot May May 09 '19 at 01:50
  • Have you tried [stack driver logging](https://console.cloud.google.com/logs/viewer)? – Cooper May 09 '19 at 02:10
  • 1
    I ended up copying the containing sheet, and re-adding the trigger. The script terminates properly after ~0.1 seconds in the copy of the sheet from the copy of the live form. I also added your code above for spurious triggers, because that was firing in my copy. Thanks Cooper. – Scot May May 09 '19 at 17:25
  • You know every once in while I find it necessary to just start a project in another sheet. I can't explain what the problem is but I find that it has worked a couple of times and as long as it works I don't feel obligated to understand it.-) The script didn't seem like it would be a problem in terms of run length. – Cooper May 09 '19 at 17:38
1

This started happening recently for me too.

According to the Execution transcript, my goGet and goPost executions appear to be running infinitely, even though the server returns a response fairly quick.

I've noticed that this only happens if I run doGet and doPost as an Anonymous user in private browsing mode. If I'm logged in, then the execution transcript behaves normally for that particular request.

I maintain a fairly large Google Apps Script with pretty high usage over the past 1.5 years. This has started to happen very recently to my script. It's alarming to see that your SO post is fairly new as well.

Copying the script to a new script temporarily fixes the issue, but eventually the new script begins to suffer this issue as well. Once the new script starts showing these symptoms, certain parts of code (particularly opening and reading Google Sheets programmatically) stop working properly and starts glitching. So, I think this issue goes beyond simply a visual issue in the Execution transcript, and it's negatively affecting the actual behavior of my other code in this script as well.

tej
  • 11
  • 1
  • I am having the same issue recently (last day or two), any update? – Elad May 16 '19 at 10:55
  • I tried working this out. Disabling and re-enabling seems to "fix" the issue. However, this needs to be done EVERY time I release a new version. Hope this helps until resolution. – Elad May 16 '19 at 11:24
  • My original script in question hasn't glitched again, but a different script has started to glitch with long execution times. Like you say, I'm hopeful this behavior is resolved soon. – Scot May May 16 '19 at 23:14
  • Yesterday I came into about 100 notifications that my scripts had failed as I had "used too much computer time." I looked through and found no issues in executions that had run as myself, but 40+ executions from other instances that had been running the last seven days continuously. Not a single execution responded to attempts to terminate it, nothing I had on a trigger would run. Today, the same instances are still running, but I no longer am limited and everything is running fine. I reached out to google support and they suggested stack overflow. -_- – ian May 29 '19 at 14:56
1

I have a Google add-on script that was working fine for months and has recently developed some similar behaviours to those described – particularly functions failing with an execution time of 0 seconds, and a type of "Unknown".

I haven't found why this is yet, though today I have contacted Google Script Support to see if they can shed any light on it.

What I have found is a workaround, though. My script started this odd behaviour at a time when I hadn't changed anything in the code. What I had done, however, was enabled the V8 runtime. If I switch it back to the old ES5 "Rhino" runtime, everything goes back to working as it used to.

See this page for info on how to do that, and give it a try. I'm still combing my script for any of the listed incompatibilities and haven't found any, but at least my users can keep using the script for now while I search!

When using the Rhino runtime, the executions that have a type of "Unknown" revert back to their previous values, which seem to all be "Web App".

axemonkey
  • 43
  • 4
  • I haven't encountered the issue again, but I haven't upgraded anything to v8 either. I have to make some changes this week to it, so I will see if it starts presenting any problems again. – Scot May Feb 25 '20 at 18:11