Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda