jeudi 25 avril 2019

Is my IF code not working due to having too many conditions?

(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 == '')
  {

...

// Eight Departments (FQA, IPQC, Legend, LPSM, MLB, Photo Printing, Routing & ____) 


    // Send if fqa & ipqc & legend & lpsm & mlb & photo & routing & drilling is ticked (Conditions for email to be sent)
    if(fqa == '✔' & ipqc == '✔' & legend == '✔' & lpsm == '✔' & mlb == '✔' & photo == '✔' & routing == '✔' & drilling == '✔')
    {
      var recipient = [test_mail,all_mail,fqa_mail,ipqc_mail,legend_mail,lpsm_mail,mlb_mail,photo_mail,routing_mail,drilling_mail] ;
      var subject = "Quality Alert for FQA, IPQC, Legend, LPSM, MLB, Photo Printing, Routing & Drilling";
    }




// Eight Departments (Inner, IPQC, Legend, LPSM, MLB, Photo Printing, Routing & ____) 


    // Send if inner & ipqc & legend & lpsm & mlb & photo & routing & drilling is ticked (Conditions for email to be sent)
    if(inner == '✔' & ipqc == '✔' & legend == '✔' & lpsm == '✔' & mlb == '✔' & photo == '✔' & routing == '✔' & drilling == '✔')
    {
      var recipient = [test_mail,all_mail,inner_mail,ipqc_mail,legend_mail,lpsm_mail,mlb_mail,photo_mail,routing_mail,drilling_mail] ;
      var subject = "Quality Alert for Inner, IPQC, Legend, LPSM, MLB, Photo Printing, 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.

Aucun commentaire:

Enregistrer un commentaire