Help please!!

50 views
Skip to first unread message

Chloe Palmer

unread,
Mar 25, 2022, 6:49:21 AM3/25/22
to Google Apps Script Community
I have a spreadsheet where I am keeping track of the expiration dates of certain licenses. I have a column set up next to the expiration dates to display "MUST RENEW" when today's date is within 30 days of the expiration date. I have been trying to create a script that will notify me by email when the status of a license changes to "MUST RENEW". So far, I have a script that emails me whenever any of the values in the column have changed. However, I cannot figure out how to only get emails when a single cell in the column changes to "MUST RENEW", not when the status changes at all.. Here is the script I have currently. If ANYONE could please tell me how to only be notified when a cell from my column changes to "MUST RENEW" I would greatly appreciate it!!!!

function checkValues(e)
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var valueToCheck = sheet.getRange(1,11).getValue();

 let msg = "Someone's Alarm Agent license is expiring within 30 days."


 if(valueToCheck = "MUST RENEW")
  {
  MailApp.sendEmail("ch...@sfxav.com", "Alarm Agent License Expring Soon", msg);
  }
}

Edward Ulle

unread,
Mar 25, 2022, 8:39:09 AM3/25/22
to Google Apps Script Community
Change  if(valueToCheck = "MUST RENEW") to  if(valueToCheck === "MUST RENEW").  In your first  case valueToCheck = "MUST RENEW" set valueToCheck to the value "MUST RENEW" so that is always true.  In the second case === means valueToCheck and the right side string "MUST RENEW" are the same variable type and the same value.

Chloe Palmer

unread,
Mar 25, 2022, 1:38:29 PM3/25/22
to Google Apps Script Community
Thank you for the advice!  I did that and now I am not getting emails at all.. I wonder if there is an issue with my ranges I input?

Chloe Palmer

unread,
Mar 25, 2022, 1:40:18 PM3/25/22
to Google Apps Script Community
Also, before when I was getting emails, even if the status changed to something else (not my trigger value), in the column, it would still email me. I think that it has been checking the entire column for the "MUST RENEW" value and finding it in a different cell so it automatically emails me when any change is made to the column..

Edward Ulle

unread,
Mar 26, 2022, 6:30:27 AM3/26/22
to Google Apps Script Community
How do you trigger this script?  Timed trigger?  Add to your code:

var valueToCheck = sheet.getRange(1,11).getValue();
console.log("value = "+valueToCheck);
console.log("type = "+typeof valueToCheck);

The next time the trigger is executed go to the script editor and on the right click on Executions.  You should see the last time the script was executed.  Open that instance and see what it says.  type should be string.

Edward Ulle

unread,
Mar 26, 2022, 7:17:55 AM3/26/22
to Google Apps Script Community
Sorry i meant to say left side
Reply all
Reply to author
Forward
0 new messages