0

Code is below

Having an issue with sending some automatic emails. I know how to have the automatic emails send based on a spreadsheet, but the complication is that the emails need to be sent in alternating situations.

Groups A & B need an email every Sunday telling them their schedule for the week. Both groups are either in-person or remote, but they alternate every week.

i.e. - Group A is in person this week, while Group B is remote. The next week they will be opposite (Group A remote, and Group B in-person)

Have any thoughts on this?

    function CheckCohortA() 
{
  // Fetch the Cohort
  var CohortRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cohorts").getRange("C2:C8"); 
  var Cohort = CohortRange.getValue();
  
  // Check Cohort
  if (Cohort = "A"){
    // Fetch the email address
    var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cohorts").getRange("B2:B8");
    var emailAddress = emailRange.getValues();
  
  //SendEmail
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; // Start at second row because the first row contains the data labels
  var numRows = 10000; // Put in here the number of rows you want to process

  // Fetch the range of cells A2:D
  var dataRange = sheet.getRange("A2:ZZ")
  
  // Fetch values for each row in the Range. I modified this after our call on 4/13 and it no references the cells E and F for th subject and message. 
  // May be easier for Principals to navigate and now this code won't have to be touched as long as the rows aren't changed I don't think. 
  var data = dataRange.getValues();
  for (i in data) {
   var row = data[i];
   var name = row[0];
   var emailAddress = row[1]; 
   var subject = row[5];
   var message = row[4]; 
   var CC = row[3];
   MailApp.sendEmail(emailAddress, subject, message,{
         cc: CC
         });
  }
  }
}
user10461998
  • 13
  • 1
  • 4

1 Answers1

0

Rearding if (Cohort = "A"){, = is the simple assignment operator. To do a comparison use == or ===. Ref. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Comparison

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Hey Ruben, Thank you for the assistance. I'm not savvy in Java. Would you mind explaining a bit about how to compare using "==" or "==="? I'm assuming 1 / 2 == 1.0 / 2.0; from the documentation means 1 and 2 equals 1.0 and 2.0? – user10461998 Sep 17 '20 at 21:59