Unknown Status in Google App Script Project Executions

有些话、适合烂在心里 提交于 2020-01-15 10:07:49

问题


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!


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/56050749/unknown-status-in-google-app-script-project-executions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!