Halo Saya mencoba mengulang array nilai dan Jika salah satu nilainya lebih besar dari 0, maka skrip harus mengirim email tertentu. Aku hanya tidak tahu bagaimana melakukannya. Apa yang saya lakukan salah?

  var TO = ['email1@gmail.com','email2@gmail.com'];
  var failedOperation = [0, 0, 0, 52, 2, 5,]
  var message1 = 'Check the sheet';
  var message2 = 'Its Ok';
  var subject = 'Your Google Spreadsheet Alert';

  for(var i in failedOperation && var j in TO){
    if(typeof failedOperation[i] > 0){
      MailApp.sendEmail(TO[j], subject, message1);
    }
    else{
      MailApp.sendEmail(TO[j], subject, message2);
    }
  } 

0
redmancunian 19 April 2020, 21:46

1 menjawab

Jawaban Terbaik
function www() {
  var TO = ['email1@gmail.com','email2@gmail.com'];
  var failedOperation = [0, 0, 0, 52, 2, 5];
  var message1 = 'Check the sheet';
  var message2 = 'Its Ok';
  var subject = 'Your Google Spreadsheet Alert';
  for(var i=0; i<failedOperation.length;i++){
    if(failedOperation[i]>0){
      MailApp.sendEmail(TO[1], subject, message1);
    }else{
      MailApp.sendEmail(TO[0], subject, message2);
    }
  }
}
1
Cooper 19 April 2020, 20:08