Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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("testemail@test.com", "subject", emailBody);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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";
  let arr = []; 
  itemResponses.forEach(function(itemResponse) {
    var title = itemResponse.getItem().getTitle();
    var response = itemResponse.getResponse();
    if(["Last Name", "Employee Number", "Business Unit"].indexOf(title)> -1){
       arr.push(response);
    }
    emailBody += title + "\n" + response + "\n\n";
  });
  // use arr, you can get your desired subject.
  const subject = arr.map(r=> r+'+');  
  sendEmail(emailBody,subject);
}

function sendEmail(emailBody,subject){
    MailApp.sendEmail("testemail@test.com", subject, emailBody);
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!