Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

JavaScript

Hello,

Can anyone help with a task I have been given with Google forms?

I found and added some JavaScript to a forms spreadsheet that emails the users responses to the forms administrator every time a form is submitted, which works great (Please see code below).

However, now they would also like the user to receive a reminder message via email after a couple of hrs of the form being submitted. I have very limited knowledge of JavaScript and have no idea how to do this, or even know where to start.

Can any JavaScript guru help please?

function sendFormByEmail(e) 
{ 
// Remember to replace XYZ with your own email address
 var email = "admin email address goes here";

// Optional but change the following variable
 // to have a custom subject for Google Docs emails
 var subject = "Booking request";

// The variable e holds all the form values in an array.
 // Loop through the array and append values to the body.

var s = SpreadsheetApp.getActiveSheet();
 var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0]; 
var message = "";


for(var i in headers)
 message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + "\n\n";

// This is the MailApp service of Google Apps Script
 // that sends the email. You can also use GmailApp here.

MailApp.sendEmail(email, subject, message);

}