0

(We're sorry, a server error occurred. Please wait a bit and try again.) error when saving and running.

When the code is 150K lines long,it could save and run. At 220K lines long,it could not save and run. The lines are mainly made out of "IF" statements. Errors started coming after the "Eight Department" code was added.(and many similar others)

function sendEmail() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var QA = ss.getSheetByName("Quality Alert");
  var QAdata = QA.getRange(3,1,QA.getLastRow() - 2,25).getValues(); 
  QAdata.forEach(function(row, i)
               {
               var customer = row[1] ;
               var part     = row[2] ;
               var s        = row[3] ;
               var id       = row[4] ;
               var defect   = row[5] ;
               var desc     = row[6] ;
               var reject   = row[7] ;
               var ok       = row[8] ; 
               var chemA    = row[9] ; 
               var chemB    = row[10] ; 
               var chemC    = row[11] ; 
               var et       = row[12] ; 
               var fee      = row[13] ; 
               var cam      = row[14] ;
               var fqa      = row[15] ; 
               var inner    = row[16] ; 
               var ipqc     = row[17] ; 
               var legend   = row[18] ; 
               var lpsm     = row[19] ; 
               var mlb      = row[20] ; 
               var photo    = row[21] ; 
               var routing  = row[22] ; 
               var drilling = row[23] ; 
               var answer   = row[24] ; 
 // Only rows with data will send out an email               
  if(customer == '')
  {
  }

  // Only send email if "email sent out" column is blank
  else if(answer == '')
  {

...

// Two Departments (chemA & ____) 
//``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````    
    // Send if chemA & chemB is ticked (Conditions for email to be sent)
    if(chemA == '✔' & chemB == '✔'){

      var recipient = [test_mail,all_mail,chemA_mail,chemB_mail] ;
      var subject = "Quality Alert for Chem A & Chem B";
    } 
//`````````````````````````````````````````````````````````````````````````````

...

// Eight Departments (Chem C, CAM, Inner, IPQC, Legend, MLB, Routing & ____) 
//`````````````````````````````````````````````````````````````````````````````

    // Send if chemC & CAM & Inner & IPQC & Legend & MLB & Routing & drilling is ticked (Conditions for email to be sent)
    if(chemC == '✔' & cam == '✔' & inner == '✔' & ipqc == '✔' & legend == '✔' & mlb == '✔' & routing == '✔' & drilling == '✔'){

      var recipient = [test_mail,all_mail,chemC_mail,cam_mail,inner_mail,ipqc_mail,legend_mail,mlb_mail,routing_mail,drilling_mail] ;
      var subject = "Quality Alert for Chem C, CAM, Inner, IPQC, Legend, MLB, Routing & Drilling";
    }

//`````````````````````````````````````````````````````````````````````````````

    GmailApp.sendEmail(recipient, subject, " ",{htmlBody: body});    
  }// End bracket for if(answer = '')
 });// End bracket for QAdata            
} // End of Function 

As im writing an automated email to the respective area if selected(15 total different that can be selected individually or simultaneously.

The 1st 150k lines are up till 7 departments and they work fine(tested it). But when the 8 department is added,it didnt work. All variables are declared and recipients are fine.

Adrian Peh
  • 70
  • 1
  • 10
  • Are the contents of the emails different for each department? Also, where are the data of the variables come from? – Thum Choon Tat Apr 25 '19 at 03:12
  • The contents are the same per selection of department.Data of variables is taken from the spreadsheet the script is linked to. – Adrian Peh Apr 25 '19 at 03:28
  • Im not sure if its cause i hit the max limit of number of rows for google app script,but i assume app script can be written as long as 1 wants it to,but it will be slower when saving and such. – Adrian Peh Apr 25 '19 at 03:40
  • Where is QAData defined? – Cooper Apr 25 '19 at 04:15
  • You might want to consider reading [mcve]. – Cooper Apr 25 '19 at 04:22
  • Added it,sry,still new to stackoverflow and programming in general,will try to make it as complete as possible. – Adrian Peh Apr 25 '19 at 04:49
  • 2
    One obvious thing for AND, double && is used not singular &. – imvain2 Apr 25 '19 at 18:31
  • You have now edited your question to eliminate the problem you are asking about; you changed the `&` to `&&` as Rubén said in the answer you accepted. The question now makes no sense at all, since it's asking about a problem that is not in the question. – Stephen P Apr 26 '19 at 16:25

1 Answers1

1

There is a syntax problem

The conditions are using & instead of &&

Ref. Logical operators


Other things to try are
  • include the opening { in the same line for each function declaration and if statement.
  • replace
    //````
    by
    //****
  • split your .gs file into several files (150k lines sounds to me to be too many for a Apps Script IDE)

Related regarding Apps Script Editor oddities:

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • After I changed the whole script && instead of & ,there is still the same error(We're sorry, a server error occurred. Please wait a bit and try again.). Thx for pointing it out though. :) – Adrian Peh Apr 26 '19 at 00:32
  • Added another thing to try – Rubén Apr 26 '19 at 00:59
  • Split your project – Rubén Apr 26 '19 at 01:19
  • Nope, does not work. 150K lines could save without issues before any changes were made.It only stopped working when the total amount of code went over 200K – Adrian Peh Apr 26 '19 at 01:41
  • That is the reason to split your project. – Rubén Apr 26 '19 at 01:42
  • To 2 separate projects? or 2 files under a single project? – Adrian Peh Apr 26 '19 at 01:43
  • By split the project I mean Go to script.google.com/create to create a new project, then move some 10k of code lines to it. Repeat as needed. – Rubén Apr 26 '19 at 01:43
  • Oh ok,will do that. – Adrian Peh Apr 26 '19 at 01:44
  • When I try to add it in through libraries,it says "The selected library must have a saved version in order to be included in another script.", but the thing is i already saved my projects. – Adrian Peh Apr 26 '19 at 01:52
  • Thx for all the help u have given,really sry for having so many questions. – Adrian Peh Apr 26 '19 at 01:57
  • No problem. By the way, I'm not a formal software engineer and I didn't work yet with 100k code lines projects as programmer but I like to read books and question about software engineering and complex projects. 220K code lines for an Apps Script project sounds to me as the result of having several [code smells](https://en.wikipedia.org/wiki/Code_smell), – Rubén Apr 26 '19 at 02:07
  • Yup,there it is mainly made up of very similar codes,with only the variables interchanging.I assume that there is a better way of doing what im currently doing, but i cant seem to find any help in that portion, which resulted in me writing such long of a code. – Adrian Peh Apr 26 '19 at 02:12
  • Maybe this could help as a starting point [My JavaScript patterns/practices stink. Where should I seek help?](https://stackoverflow.com/q/8167859/1595451) – Rubén Apr 26 '19 at 02:26