I created a google spreadsheet to track samples from vendors. I added 4 OnEdit functions to send email to two separate email addresses once the sample feedback is provided (approval cell is filled out with "Y" for approved or "N" for not approved. one function for each email address for a total of 4). However, I also tried to create a 5th OnEdit function to trigger an email (recipient based on the row) once the tracking checkbox is clicked. Unfortunately, that 5th OnEdit function is not working properly. Can you please advise how to solve this? Wondering if I should put all of these together in one function (and how, because it's my first time playing around with Apps Script), or if there is something wrong with the coding that is causing this not work properly.
Currently, the email goes out when ANY cells of that specific row are changed, and not just when the checkbox is clicked. Not only that, but the function has a huge error rate and is basically not working at all.
FUNCTION:
function onEdit(e) {
var range = e.range;
var col = range.getColumn();
var row = range.getRow();
var edited_value = e.value;
var ss = e.range.getSheet();
if(col == 5 && edited_value == "TRUE" && ss.getRange("R"+row).getValue() == "")
{
Browser.msgBox("Check If You Have an Email Address in column R ")
}else
{
var to = ss.getRange("R"+row).getValue();
var subject = ss.getRange("G"+row).getValue();
var Email_body = ss.getRange ("D"+row).getValue();
MailApp.sendEmail(to,subject,Email_body)
}
}