I have a Google form that works great. Inside that form i also have scripts written up that send out emails. These also work great.
What i dont have is a way to make those scripts trigger and run on their own. For now, when the form is edited, i get a notification email. I then have to log into the spreadsheet and manually run my email script(s).
I want the spreadsheet to run the scripts automatically and send the email when data is added from the form. I tried the onEdit below but that only works if i have the spreadsheet open and i launch it. Is there another way to run a script automatically after a form is edited without having to open it up?
Here is a basic email code + my onEdit i tried to make work.
// Ran when the spreadsheet is edited
function onEdit(){
emailEOnEdit();
}
// Sends an email when the New User Request Form is edited
function emailEOnEdit(row){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var subject = "Test Email On Edit";
var recipients = "user@domain.com"
var message = "<HTML><BODY>"
+ "<P>" + sheet.getRange("E1").getValues()
+ "</HTML></BODY>";
MailApp.sendEmail(recipients, subject, "", {htmlBody: message});
}
Have you tried the onFormSubmit trigger?