I'm looking to see if this is possible, I have developed a google form, where there is a date picker, In the spreadsheet output, Im looking to run a check to see if the user is under 18 or not. If the user is under 18 I wish to trigger an email.
I have got the email part working, but only when I execute the code from within the google scripts window. (I still need to get the trigger working, it gives me You do not have permission to call sendEmail
) But I can run it from within the google script environment no problem
I know how I would calculate the date, IE getTheYear() - getCurrentYear()
, and wrap this within an IF else block that contains the email execution script.
Here is my attempt I don't think I'm to far off
function ageChecker() {
var sheet = SpreadsheetApp.getActiveSheet();
var valTEST = sheet.getRange("I2").getValue();
var cell = sheet.getActiveCell();
var msg="Warning Student X is under 18"
var ui = SpreadsheetApp.getUi();
// Get the actual cell value
// var response = ui.alert(valTEST, ui.ButtonSet.YES_NO);
// valTest output TUE SEPT 17 1991 00:00:00 GMT+0100 (BST)
var d = new Date();
var timeStamp = d.getTime(); // Number of ms since Jan 1, 1970
//var response = ui.alert(d, ui.ButtonSet.YES_NO);
var age = valTEST-d;
var response = ui.alert(age, ui.ButtonSet.YES_NO);
if(valTEST==18) {
MailApp.sendEmail("email@domain.ie","Student Error", msg);
}
}