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

217
Vistas
Sending an email notification if an event happens next week, in Google Apps Script

The task is pretty simple, I have a Google Sheet that contains a column with calculated dates. I want to be alerted by email, every time there is a date in that column that is less than a week away from today. My current code is:

function DueDateAlert() {
  
  var due_date_range = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Main").getRange("J2:J56"); 
  var due_date = due_date_range.getDisplayValues(); 
  var now = new Date();
  var recipients = "johndoe@gmail.com";
  var nextWeek = now.setDate(now.getDate() + 7);
  var counter = 0;
  for(i in due_date){
    if (i < nextWeek){
      counter = counter+1  
    }}
  if (counter > 0){
      var message = " Task coming up ,Please consult the  Schedule "; 
      var subject = 'Task Alert';
      MailApp.sendEmail(recipients, subject, message);

}

The problem is that the script executes no matter the value in the cell. For some reason I get alerted even if the cells are empty. Any ideas? Much appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The line: if (i < nextWeek)

i is a number. (From zero to 55, I suppose).

nextWeek is a date.

You're comparing number with date. It doesn't make sense.

Probably you need: if (new Date(dueDate[i]) < nextWeek).

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