I have a Google Spreadsheet with 4 columns including Products, Salesperson, Category and Status. What I am trying to reach is whenever a user choose Yes option on Status column and if that product category is also G, then sending an email using the MailApp. The e-mail should include the product value as well.
So far, I was able to sending an email. But I've really confused about the offset concept here and was not able to send the product in the email
The spreadsheet: https://docs.google.com/spreadsheets/d/1wVr0SGryNNvorVdDZEY1E6UDgh25_A5A2LhN1UNbIHE/edit?usp=sharing
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var sheetName = sheet.getName();
var r = sheet.getActiveCell();
var cell = sheet.getActiveCell().getA1Notation();
if(ss.getActiveCell().getColumn() !== 5) return;//
var row = sheet.getActiveRange().getRow();
var cellvalue = sheet.getActiveCell().getValue().toString();
var prod = sheet.getRange().offset(0, -2).getValues();
var cat = cellvalue.offset(0, -1).getValues();
var recipients = "[email protected]";
var message = '';
if(cellvalue === 'Yes' && cat === 'G') {
message = cell + ' in Sheet ' + sheetName + ' was changed to YES.';
var subject = 'Cell Changed to YES';
var body = message + ss.getUrl() + ' to view the changes' + prod;
MailApp.sendEmail(recipients, subject, body);
}
}
MailApp.sendEmail, using simple triggers likeonEdit(e). You have to use Installable Triggers. - Carlos M