Code for this video is posted below.
[code]
// Word Based Email Alert System
// Kurt Kaiser, 2017
// Declarations
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
// Go through recent submission, check for alert word
function checkSubmission() {
for (var i = 1; i < lastColumn; i++) {
if ("Friday" == sheet.getRange(lastRow, i).getValue()) {
return sheet.getRange(lastRow, 4).getValue();
}
}
return false
}
function lastSubmission() {
this.name = sheet.getRange(lastRow, 2).getValue();
Logger.log("NAME: " + this.name);
this.day = sheet.getRange(lastRow, 3).getValue();
this.time = sheet.getRange(lastRow, 4).getValue().toLocaleTimeString();
return this
}
// Puts together all parts of the alert email
function sendAlertEmail(data) {
MailApp.sendEmail({
to: "kurtbkaiser@gmail.com",
subject: "Alert – Friday Requested",
htmlBody: htmlEmail(data)
})
}
// —————————————-
function main() {
if (checkSubmission() != false) {
var data = lastSubmission();
sendAlertEmail(data);
}
}
HTML Email
[code]
// Kurt Kaiser, 2017
// Email
function htmlEmail(data){
return ‘<!DOCTYPE html><html><head><base target="_top"></head><body style="text-align: center;font-family: Arial;">\
<div id="center" style="width:300px;border: 2px dotted grey;background:#ececec;margin:25px;margin-left:auto;\
margin-right:auto;padding:15px;"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Simple_Alert.svg/600px-Simple_Alert.svg.png"\
width="180" style="margin:10px 0px"><br /><div style=" border: 2px dotted grey;background:white;margin-right:auto; margin-left:auto;\
padding:10px;"><h2>Alert</h2><h3>There was a new submission that contained the keyword. <br /><br />’
+ data.name + ‘<br />’ + data.day + ‘<br />’ + data.time + ‘<br /></h3></div></body></html>’
}
//
[/code]
HTML
No Comments Yet