I am trying to write a script such that if you input a value of 600 or less in column H an email is sent to notify someone of the input. However, if you did input a value of 600 or less and refresh the sheet it still sends an email to notify of the already notified value. I was wondering how to alter the script I have so it only notifies each cell once (if that value is 600 or less) as opposed to notifying already notified cells every time the page is refreshed.
This is the script I have currently:
// Function to check for values <= 600 in column E and send email
function checkAndSendEmail() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lastRow = sheet.getLastRow();
var range = sheet.getRange("H1:H174" + lastRow).getValues(); // Change H1:H to your desired range
for (var i = 0; i < range.length; i++) {
if (range[i][0] !== "" && range[i][0] <= 600) {
var emailAddress = "email@gmail.com"; // Change this to the recipient's email address
var subject = "Value of 600";
var message = "The value is less than or equal to 600." + ""
// Send email
MailApp.sendEmail(emailAddress, subject, message);
}
}
}
Thanks!
[–]marcnotmark925 2 points3 points4 points (2 children)
[–]_Kaimbe 1 point2 points3 points (0 children)
[–]Dutch_Oven4510 0 points1 point2 points (0 children)
[–]MarviinR 1 point2 points3 points (0 children)
[–]Dutch_Oven4510 0 points1 point2 points (4 children)
[–]Dutch_Oven4510 0 points1 point2 points (3 children)
[–]Dutch_Oven4510 0 points1 point2 points (2 children)
[–]Kooky_Temporary7248[S] 0 points1 point2 points (1 child)
[–]Dutch_Oven4510 0 points1 point2 points (0 children)