Google Form Sheets Script Editor - email field filled out
- or -
Post a project like this2558
£15(approx. $19)
- Posted:
- Proposals: 1
- Remote
- #1524461
- Awarded
Description
Experience Level: Entry
General information for the website: I have a google form that collects data and sends me an email when that happens with what has been completed
Description of requirements/features: I can send the email but it shows every single column including the blank ones. I would like the email to only show the data that has been filled out by the user.
function sendFormByEmail(e)
{
// Remember to replace this email address with your own email address
var email = "email@domain.com, email@domain.com";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
var subject = "Horizons Form: ";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
for(var i in headers)
message += headers[i] + ': '+ e.namedValues[headers[i]].toString() + "\n\n";
// Insert variables from the spreadsheet into the subject.
// In this case, I wanted the new hire's name and start date as part of the
// email subject. These are the 3rd and 16th columns in my form.
// This creates an email subject like "New Hire: Jane Doe - starts 4/23/2013"
subject += e.namedValues[headers[2]].toString() + " - from " + e.namedValues[headers[1]].toString();
// Send the email
MailApp.sendEmail(email, subject, message);
// Based off of a script originally posted by Amit Agarwal - www.labnol.org
// Credit to Henrique Abreu for fixing the sort order
}
Extra notes:
Description of requirements/features: I can send the email but it shows every single column including the blank ones. I would like the email to only show the data that has been filled out by the user.
function sendFormByEmail(e)
{
// Remember to replace this email address with your own email address
var email = "email@domain.com, email@domain.com";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
var subject = "Horizons Form: ";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
for(var i in headers)
message += headers[i] + ': '+ e.namedValues[headers[i]].toString() + "\n\n";
// Insert variables from the spreadsheet into the subject.
// In this case, I wanted the new hire's name and start date as part of the
// email subject. These are the 3rd and 16th columns in my form.
// This creates an email subject like "New Hire: Jane Doe - starts 4/23/2013"
subject += e.namedValues[headers[2]].toString() + " - from " + e.namedValues[headers[1]].toString();
// Send the email
MailApp.sendEmail(email, subject, message);
// Based off of a script originally posted by Amit Agarwal - www.labnol.org
// Credit to Henrique Abreu for fixing the sort order
}
Extra notes:
Dominic C.
100% (6)Projects Completed
3
Freelancers worked with
4
Projects awarded
33%
Last project
7 Apr 2019
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
Hi,
Why don't you use to check before sending the email? Check if it is null then do nothing else send the email.
Thanks
381200
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies