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

126
Visualizações
Google App Script IF statement for Sending Emails

Just want to ask some help regarding with my coding in Google App Script.

Objective: Am trying to send emails once I satisfy the 3 condition (the 2 condition is in the same column). And once the script already sent an email to that specific control number the script shouldn't send again to that transaction. However it still sending emails even if the script already sent to that transaction. I can't find where the problem is or if am not satisfying the condition I set.

Column SubmissionStatus have "Final, Cancelled, Draft" Column processBy have ("ADMIN" only)

  if (submissionStatus !== "Draft" && processBy !== "") { // Prevents sending duplicates  
  var subject = "Cash_Advance ";
  MailApp.sendEmail(currentEmail, subjectline, messageBody);
  sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
  // Make sure the cell is updated right away in case the script is interrupted
  SpreadsheetApp.flush();
  } //close if statement

  if (submissionStatus !== "Cancelled" && processBy !== "") { // Prevents sending duplicates  
  var subject = "Cash_Advance ";
  MailApp.sendEmail(currentEmail, subjectline, messageBody);
  sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
  // Make sure the cell is updated right away in case the script is interrupted
  SpreadsheetApp.flush();
  } //close if statement
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can simply merge those two if statement into one, maybe that's why it is sending email more than once.

By using submissionStatus === "Final"

In context of your latest edit:-

Column SubmissionStatus have "Final, Cancelled, Draft" Column processBy have ("ADMIN" only)

Modification:

if (submissionStatus === "Final" && processBy !== "") // Prevents sending duplicates  
{ 
          var subject = "Cash_Advance ";
          MailApp.sendEmail(currentEmail, subjectline, messageBody);
          sheet.getRange(startRow + i, 38).setValue(EMAIL_SENT +" "+ Date()); // column AL
          // Make sure the cell is updated right away in case the script is interrupted
          SpreadsheetApp.flush();
 } //close if statement
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