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

207
Visualizações
Coding google sheets script

i work in insurance, and i have a Google Sheets for all my coworkes where i take note of all policies that we make with external collaborations. I need this: if today a policy expire, the code should send an email to my company addres. Now the code that i used is working, but it only work for one sheet, and send mail even if he finds black spaces. enter image description here

function alertSender() {
  var today = new Date(); 
  var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
  for(n=1;n<values.length;++n){
    var cell_date = values[n][5];
    var expired = today > cell_date;
    if (expired) {
      MailApp.sendEmail(values[n][6], 'Mail automatica', 'Servizio scaduto per il sig. ' + values[n][0]);
      Logger.log('Mail inviata all\'indirizzo ' + values[n][6] + ' del sig. ' + values[n][0]);
    }
  }
}

This is the code i used, where Date (5) is column F and mail (6) is column G.

Just execution started and execution completed, no errors but no emails, and yes i put in and expired date for test purposes

https://docs.google.com/spreadsheets/d/1JXgpU5QkV3XlhXh6VMVy_sTeDkXr_Egr9lzhfyno8O4/edit?usp=sharing

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try

function alertSender() {
  var today = new Date();
  SpreadsheetApp.getActiveSpreadsheet().getSheets().forEach(sheet => {
    var values = sheet.getDataRange().getValues().splice(1).filter(r => r[5] != '');
    for (n = 1; n < values.length; ++n) {
      var cell_date = values[n][5];
      var expired = today > cell_date;
      if (expired) {
        MailApp.sendEmail(values[n][6], 'Mail automatica', 'Servizio scaduto per il sig. ' + values[n][0]);
        Logger.log('Mail inviata all\'indirizzo ' + values[n][6] + ' del sig. ' + values[n][0]);
      }
    }
  })
}

references

  • getSheets()
  • forEach
  • splice()
  • filter
about 4 years ago · Juan Pablo Isaza Relatório
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