Google Apps Script - How to change value in spreadhseet cell after sending an automatic email?

Viewed 14

I have written code which send an email to the emailadress in B2 when the value 1 is in cell J2. However, I want my script return the value 1 in cell K2 when the script has sent that mail such that I can make sure that the person will not receive the same mail again when it has been sent.

function CheckPresence() {
  // Fetch the presence of dancer
  var dancerPresenceRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Blad1").getRange("J2"); 
  var dancerPresence = dancerPresenceRange.getValue();
  var dancerPresenceDateRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Blad1").getRange("F2"); 
  var dancerPresenceDate = dancerPresenceDateRange.getValue();
  // Check the presence of dancer
  if (dancerPresence = 1){
    // Fetch the email address
    var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Blad1").getRange("D2");
    var emailAddress = emailRange.getValue();
    // Send confirmation mail of presence
    var message = 'Leuk dat je aanwezig was bij de proefles op ' + dancerPresenceDate + '!'; // Second column
    var subject = 'Proefles gevolgd'; 
    MailApp.sendEmail(emailAddress, subject, message);
    }
}
    

0 Answers
Related