How to automatically send an email when a condition is met. This uses an installable On Edit trigger and must be authorized.
Important Notes:
* This uses both .toLocaleDateString() and .toLacaleString(). The former only returns the date “11/13/2020,” the latter returns the date and time “11/13/2020 , 2:12:17 PM”
Sheet (to copy):
https://docs.google.com/spreadsheets/d/1_aHDxbkBg_M3–nlN3et3TdvLrSNX31I2Ej4MEyNv1E/edit#gid=0
Script:
function sendMailEdit(e){
if (e.range.columnStart != 5 || e.value != “Approved”) return;
const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,4).getValues();
let n = rData[0][2];
let d = new Date(rData[0][0]).toLocaleDateString(“en-US”);
let items = rData[0][3];
let loc = rData[0][1];
let now = new Date().toLocaleString(“en-US”);
let msg = “Order number ” + n + ” (” + d + “) containing ” + items + ” items from ” + loc + ” Approved at ” + now;
Logger.log(msg);
GmailApp.sendEmail(“receipient_email_address”, “Approved Order”, msg)
}