'Google Forms Custom Subject Line
I am new to Apps Script and I have found some great information on this site to automate an email with the form responses anytime someone submits a new Google Form Response. However, I want the subject line to be the answers they submitted for questions "Last Name", "Employee Number", and "Business Unit". I've tried to modify a few different answers from other questions here and I haven't been able to get them to work. I really don't want to use an add-on as this will have employee information. Below is the script I am using now. It works great, but I just need a way to change the subject line. Thank you all!
function createFormSubmitTrigger() {
var form = FormApp.getActiveForm();
var currentTriggers = ScriptApp.getProjectTriggers();
if(currentTriggers.length > 0)
return;
ScriptApp.newTrigger("onFormSubmit").forForm(form).onFormSubmit().create();
}
function onFormSubmit(e) {
var formResponse = e.response;
var itemResponses = formResponse.getItemResponses();
var emailBody = "New form response:\n\n";
itemResponses.forEach(function(itemResponse) {
var title = itemResponse.getItem().getTitle();
var response = itemResponse.getResponse();
emailBody += title + "\n" + response + "\n\n";
});
sendEmail(emailBody);
}
function sendEmail(emailBody)
{
MailApp.sendEmail("[email protected]", "subject", emailBody);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
