I'm pretty new at coding so I apologize if this is something simple that I'm overlooking or missing.
function emailTest() {
var sheet=SpreadsheetApp.getActiveSheet();
var currentROI=sheet.getRange("D2").getValue();
var previousROI=sheet.getRange("D3").getValue();
if((currentROI/previousROI)-1<=.10) {
pctChange=currentROI/previousROI-1;
MailApp.sendEmail({
to:"test@test.com",
subject:"Test email for auto-trigger",
htmlBody:"sampleROI increased by " + pctChange + "from " + previousROI +" to " + currentROI +"."
});
}
}
My code is above. Essentially what I want to do is find out if the cell value drops goes under 10%, then send an email to a given account.
I eventually want this to do "if the current cell goes up or down by 15% from the previous day, then send an email to x people".
It looks like the code is saving just fine but once I try to add a time trigger, it gives me the "a server error occurred" error message which, after extensive reading, seems like its a code issue.
Edit:
It's actually running now (forgot to add permissions) but if I could get some help with formatting the result and making it check if it goes up or down 15% that would be super helpful.