I am trying to have Google Sheets send an email when column 5 contains the exact string “Yes”. If I personally trigger the script, it works just fine but I want it to automatically trigger on edit but it does not work for some reason. Please excuse the sloppiness of my script. I have rewritten several times and am still fairly new to Javascript. Thanks for any help!!
function ifStatemenet(){
var sheet = SpreadsheetApp.getActiveSheet();
var row = sheet.getDataRange();
var numRows = row.getNumRows();
var values = row.getValues();
for(i in values){
var row = values[i];
if (row[4] == “Yes”) {
sendEmail();
}
}
}
function sendEmail(){
var sheet = SpreadsheetApp.getActiveSheet();
var row = sheet.getDataRange();
var values = row.getValues();
var row = values[i];
var recipient = row[1,1];
var subject = “Internal Repair Form”;
var body = row[1,5];
MailApp.sendEmail(recipient, subject, body)
};