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

226
Vistas
Avoid Having Duplicate Email Everytime Googlesheet is edited by Users (Google Script)

I am new in javascript and still learning. I had made a Spread Sheet as a tracker of work data with multiple users working on it. WorkArea tabWorkArea is where we tag the time and if completed. Another tab is the Error Tab ErrorTAB is a query tab and shows envelope number if tagged incorrectly (no time input and was tagged completed). In the error tab there is a counta formula on cell "S3" which will determine if there an error and will show "TRUE". My problem is that my code is sending too many emails every time users make an edit. If possible, I want it to send email once. Can you help me on this?

Here is the code I made with onEdit trigger

function sendEmail(e) {
  var sp = PropertiesService.getScriptProperties();
  var errorTab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Error');
  var cellRef = errorTab.getRange('S3').getValue();
  var dataRef = "Kindly Check " +  errorTab.getRange('B3').getValue() +  errorTab.getRange('H3').getValue() + errorTab.getRange('N3').getValue();
  var oldValue  = sp.getProperty('S3') || 0;

  if(cellRef == false && cellRef == oldValue) return;
  else 
  var option = {
    cc: "admin1@gmail.com",
  }
  {GmailApp.sendEmail("admin@gmail.com",
  "Dating Contracts Email Notification for Error Tab",
   dataRef,option);
   sp.getProperty('S3', cellRef);
  }
}

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

0

From your following replying,

I want your idea that if email sent it will show sent on T.

when you want to put sent to the column "T" (in your situation, the cell "T3") after the email is sent, how about the following modification?

By the way, I think that sp.getProperty('S3', cellRef); occurs an error. Because getProperty is only one argument. I thought that you might have wanted to be sp.setProperty('S3', cellRef);.

Modified script:

function sendEmail() {
  var sp = PropertiesService.getScriptProperties();
  var errorTab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Error');
  var [cellRef, sent] = errorTab.getRange('S3:T3').getValues()[0];
  if (sent == "sent") return;
  var [b3,,,,,,h3,,,,,,n3] = errorTab.getRange('B3:N3').getValues()[0];
  var dataRef = "Kindly Check " + b3 + h3 + n3;
  var oldValue = sp.getProperty('S3') || 0;
  if (cellRef == false && cellRef == oldValue) return;
  var option = { cc: "admin1@gmail.com" }
  GmailApp.sendEmail("admin@gmail.com", "Dating Contracts Email Notification for Error Tab", dataRef, option);
  errorTab.getRange("T3").setValue("sent")
  sp.setProperty('S3', cellRef);
}
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