We have two sheets:
- Sheet1 - It has one column & 10,000 rows with drop-down values - "approved" and "not approved".
- Sheet2 - It has email-related details i.e. email, subject, message-approved, message-not-approved.
I want to send an automatic email if the drop-down value is changed. I want to send message-approved if someone changes Sheet1 dropdown selection to "approved" and message-not-approved if it is changed to "not approved".
I have been able to successfully send the email message when i run it in script editor but it is not triggering on drop down change. I understand that i need to use onedit trigger but not sure how to do that. Any help is appreciated. Here is the code.
function sendEmail(){
var ss1 = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss1.getSheetByName('Sheet1');
var valueToCheck = sheet1.getRange("A2").getValue();
if(valueToCheck == "approved"){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet2=ss.getSheetByName('Sheet2');
var emailAddress = sheet2.getRange(2,1).getValue();
var subject = sheet2.getRange(2,2).getValue();
var message = sheet2.getRange(2,3).getValue();
MailApp.sendEmail(emailAddress, subject, message);
}
else{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet2=ss.getSheetByName('Sheet2');
var emailAddress = sheet2.getRange(2,1).getValue();
var subject = sheet2.getRange(2,2).getValue();
var message = sheet2.getRange(2,4).getValue();
MailApp.sendEmail(emailAddress, subject, message);
}
}