Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
How to stop my script continuously issuing emails?
function reminder() {
  var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var data = sh.getDataRange().getValues();
  var d = new Date().getTime();
  for (var i = 1; i < data.length; i++) {
    var recipients = data[i].slice(3, 6).filter(String).join(",");
    if (recipients == "") continue;
    if (data[i][6] <= new Date(d + 7 * 24 * 60 * 60 * 1000) && data[i][6] >= new Date(d + 5 * 24 * 60 * 60 * 1000) && data[i][7] == '') {
      MailApp.sendEmail({
        to: recipients,
        subject: 'Reminder Process Update Required in 1 week',
        htmlBody: 'Hello ' + data[i][2] + ', the  process page for <b>' + data[i][1] + '</b> is due for review in 1 week. Please review the content and contact the Process team before its due date if amendments are required.'
      });
      sh.getRange(i + 1, 9).setValue('sent');
    }
    else if (data[i][6] <= new Date(d + 30 * 24 * 60 * 60 * 1000) && data[i][6] >= new Date(d + 28 * 24 * 60 * 60 * 1000) && data[i][7] == '') {
      MailApp.sendEmail({
        to: recipients,
        subject: 'Reminder Process Update Required in 1 month',
        htmlBody: 'Hello ' + data[i][2] + ', the process page for <b>' + data[i][1] + '</b> is due for review in review in 1 month. Please review the content and contact the Process Mapping team before its due date if amendments are required.'
      });
      sh.getRange(i + 1, 8).setValue('sent');
    }
  }
}

Currently Im facing this issue 1), If the due date is 1 week on the table the script will continuously issue the email and apply "sent" onto the table though still send the emails, 2). If the due date is 1 month then it will issue the email however once "sent" is inputted into the sheet no further emails will be issued which is fine until this causes an issue when the date becomes to 1 week before then it will not issue the second reminder email advising its due

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda