0

Hello I'm trying to loop through an array of values and If the any of the values is bigger than 0, then the script should send a specific email. I just cant figure it out how to do it. What am I doing wrong?

  var TO = ['[email protected]','[email protected]'];
  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

1 Answer 1

1
function www() {
  var TO = ['[email protected]','[email protected]'];
  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);
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.