Send email when cell value equals 29

I am having trouble with my google sheets script and I wondered if anyone had any advice for a beginner. I want my script to check a cell value (Sheet1, H2), then send an email if the value = 29. However, at the moment it will send an email whatever value it returns, I don't think my if statement works correctly. Any ideas would be really appreciated.

enter image description here

function CheckExpiry() {
  // Fetch the days till expiry.
  var ExpiryDataRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("H2"); 
  var ExpiryData = ExpiryDataRange.getValue();
  // Check expiration
  if(ExpiryData = 29){
    // Fetch the email address
    var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("C2");
    var emailAddress = emailRange.getValue();
    // Send Alert Email.
    var message = 'You are recieving this email as harness # is up for inspection soon, current inspection expires in the following number of days: ' + ExpiryData; // Second column
    var subject = 'Your Harness Spreadsheet Alert';
    MailApp.sendEmail(emailAddress, subject, message);

Answers 1

Related Questions