I want an email to be sent when a cell is changed from "No" to "Yes" in column C from a particular sheet - sheet1.
The email body would need to include information from cells in columns D,E,F,G,H,I,J from the same row as the cell that changed to Yes, in addition to of course the email subject and email recipient.
I'd like this script to be modified to do that or if there is another script that could do the above.
function sendNotification(e){
if(e.range.getColumn()==3 && e.value=='YES'){
var recipients = "***********@gmail.com";
var subject = "Update"+e.range.getSheet().getName();
var body = "This cell has changed";
var valColB=e.range.getSheet().getRange(e.range.getRow(),2).getValue();
MailApp.sendEmail(recipients, subject, body)
}
}
Hello XYZ,
Please find order details below.
{Cell D} (Its in this format xxxxxx-ABC0001, I need the second part after "-" from this cell here)
Size - Width: {Cell E} x Height: {Cell F}
Quantity - {Cell H}
- It needs to be tube {Cell I}.
- Shipment to {Cell J}.
- Order image is {Cell G}
The order is for a customer from {Cell J}
Thanking you,
ABC
The subject needs to have
{Cell J} New Order No. {Cell D}
The recipient is always the same
Any help would be highly appreciated. Thanks.
Update - Solution - Thanks to Ron
function sendNotification(e){
var s = SpreadsheetApp.getActiveSpreadsheet();
var ss = s.getSheetByName("Order Details")
if(e.range.getColumn()==3 && e.value=='Yes'){
var cell = ss.getActiveCell();
var row = cell.getRow();
//var row = ss.getRange().getRow();
//var sku = ss.getRange("D2").getValue();
var sku = ss.getRange(row,4).getValue(); //Column D
var array1 = [{}]; array1 = sku.toString().split("-")
//var sku = "D2"; var array1 = [{}]; array1 = name.toString().split("-")
var sizewidth = ss.getRange(row,5).getValue(); //Column E
var sizeheight = ss.getRange(row,6).getValue(); //Column F
var qty = ss.getRange(row,8).getValue(); //Column H
var country = ss.getRange(row,10).getValue(); //Column J
var tube = ss.getRange(row,9).getValue(); //Column I
var paintingimage = ss.getRange(row,7).getValue(); //Column G
var orderlink = 'HYPERLINK("http://testly/Km45S", "Order Details")';
MailApp.sendEmail({
to: "[email protected]",
subject: country + " New Order No. " + array1[1], // note the spaces between the quotes...
htmlBody: "Hello XYZ, <br>"+
"Please find order details below. <br><br>"+
sku + "<br><br>" +
"Size - Width: " + sizewidth + " x " + "Height: " + sizeheight + "<br><br>"+
"Quantity - " + qty + "<br><br>"+
"- It needs to be tube rolled"+
"- Shipment to " + country + "<br>" +
"- Order image is " + paintingimage + "<br>" +
"The order is for a customer from " + country + "<br><br>" +
"Thanking you, <br>" +
"Abc",
})
}
}