vendredi 25 juin 2021

Google App Script IF function checking only one row, and applying the result to all rows

I seem to be going quite wrong somewhere.

I'm writing a script that will automatically send out a reminder email if a Google sheet cell turns to "Yes".

The problem is my script seems to read it as: if the second row has a "yes" it will return true for all rows and send out an email to everyone, regardless of the other rows saying "yes" or "no". if any other row has a yes, then it seems to be completely ignored.

Defining the range to check:

 //looping through all of the rows
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];


// Creating where the if statement is check
var ss = SpreadsheetApp.getActiveSheet();
    var thisQuarter = ss.getRange("H2:H50").getValue();

The IF statement to check against:

// checking for this quarter
if (
  thisQuarter == "Yes") {
      var subject =
        'Your BCP is due to expire this quarter: ';
      MailApp.sendEmail(emailAddress, subject, message,);
      Logger.log('this quarter');
    }

   

  
   
    }
  }

If anyone could give me a couple pointers as to where I'm going wrong, that would be greatly appreciated.

Thank you,

Aucun commentaire:

Enregistrer un commentaire