I need Google Spreadsheet to send an email when there's changes to a cell.
Problem is, what appears in this cell is determined by values of another sheet (I used if and filter functions for this).
The usual,
if(cell.indexOf('F')!=-1){
MailApp.sendEmail(emailAddress, subject, message);
}
doesn't seem to capture the change in the cell since the change is brought about by a formula compiling data from another sheet, however, it does send me an email if I were to manually type in stuff in column F.
The following is my whole code in the script editor:
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("sendNotification")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onEdit()
.create();
};
function sendNotification(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = ss.getActiveCell().getA1Notation();
var dataRange = sheet.getRange(2, 1, 2, 2);
var data = dataRange.getValues();
for (i in data) {
var row = data[i]
var emailAddress = row[0];
var message = row[1];
var subject = "Job exceeded time allocated";
if(cell.indexOf('F')!=-1){
MailApp.sendEmail(emailAddress, subject, message);
}
}
}