Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

320
Vistas
(GAS) Email Spreadsheet range based on date input in the cell

Below is a script that is SUPPOSED TO email me a range of not empty rows in the "Files Change Report" sheet on the date written in cell H2 of the same sheet. However, when testing the script, no matter what is in H2, the email is still sent. Could anybody advise what is wrong with the script? Thank you.

function email() {
    
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var bulk = ss.getSheetByName("File Change Report");
    
      var lastrow = bulk.getLastRow();
    
      var email = bulk.getRange("E1").getValue();
      var emailFromName ="David Baker";
      var emailSubject = "UPDATES TO YOUR FILES";
    
      const WebLink = 'https://docs.google.com/forms/d/e/123...'
      var emailFooter = "To stop notifications<a href=" + WebLink + ">press here.</a>";
    
      var data1 = bulk.getRange(2, 5, lastrow).getValues(); // row no column E
      var data2 = bulk.getRange(2, 6, lastrow).getValues(); // date updated column F
      var data3 = bulk.getRange(2, 7, lastrow).getValues(); // file name column G
      var data4 = bulk.getRange(2, 4, lastrow).getValues(); // file url column D
      
      var SendDateRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("File Change Report").getRange("H2"); 
      var SendDate = SendDateRange.getValue();
      var curDateRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("File Change Report").getRange("H4"); 
      var curDate = curDateRange.getValue();
    
      for(var i in data1){
      if (SendDate.toString() == curDate.toString()){ table += "<tr><td width='7' style='padding-right:5px' align='right'>" + data1[i] + "</td><td style='padding:0px'>" + data2[i] + "</td><td style='padding: 0px 0px 0px 20px'><a href='" + data4[i] + "'>" + data3[i] + "</a></td></tr>"; //top right bottom left
      }
    
      var message = ""
      var table ="";
        
      message ="Files below have been updated:<br/><br/> <table style='margin-left:10px'><tr><th></th><th align='left'>Date</th><th align='left' style='padding: 0px 0px 0px 20px'>File Name</th></tr>" + table + "</table></li>"+ "<br><small> "+emailFooter+" </a></small>";
    
      MailApp.sendEmail(email,emailSubject, message, {name: emailFromName, htmlBody: message});
    
      var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Fetch all files");
        array = [];
        ss.getRange("A2:G") // Choose the range here.clear();
        .clearContent();
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

From the question

However, when testing the script, no matter what is in H2, the email is still sent.

Change

if (SendDate.toString() == curDate.toString()){ table += "<tr><td width='7' style='padding-right:5px' align='right'>" + data1[i] + "</td><td style='padding:0px'>" + data2[i] + "</td><td style='padding: 0px 0px 0px 20px'><a href='" + data4[i] + "'>" + data3[i] + "</a></td></tr>"; //top right bottom left
      } // <--- this bracket should be moved 
    
      var message = ""
      var table ="";
        
      message ="Files below have been updated:<br/><br/> <table style='margin-left:10px'><tr><th></th><th align='left'>Date</th><th align='left' style='padding: 0px 0px 0px 20px'>File Name</th></tr>" + table + "</table></li>"+ "<br><small> "+emailFooter+" </a></small>";
    
      MailApp.sendEmail(email,emailSubject, message, {name: emailFromName, htmlBody: message});
    
      var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Fetch all files");
        array = [];
        ss.getRange("A2:G") // Choose the range here.clear();
        .clearContent();

to

if (SendDate.toString() == curDate.toString()){ table += "<tr><td width='7' style='padding-right:5px' align='right'>" + data1[i] + "</td><td style='padding:0px'>" + data2[i] + "</td><td style='padding: 0px 0px 0px 20px'><a href='" + data4[i] + "'>" + data3[i] + "</a></td></tr>"; //top right bottom left
       
    
      var message = ""
      var table ="";
        
      message ="Files below have been updated:<br/><br/> <table style='margin-left:10px'><tr><th></th><th align='left'>Date</th><th align='left' style='padding: 0px 0px 0px 20px'>File Name</th></tr>" + table + "</table></li>"+ "<br><small> "+emailFooter+" </a></small>";
    
      MailApp.sendEmail(email,emailSubject, message, {name: emailFromName, htmlBody: message});
    
      var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Fetch all files");
        array = [];
        ss.getRange("A2:G") // Choose the range here.clear();
        .clearContent();
} // <--- this is new position of the if bracket 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda