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

180
Visualizações
Share variable from .gs into .html in Google Apps Script

I'm trying to get respondents to a Google Form survey fill another survey, but some of their responses will be pre-filled based on the first survey. Basically, want all of their responses attached to the unique person, without making them answer same questions again. And it must be two surveys, not a continuation. In this example, I'm only pre-filling their email address, but it may be more fields.

So in Google Apps Script, I've got a Code.gs and and Email1.html scripts as follows:

function confirmationEmail1(e) {
  
  var htmlBody= HtmlService.createHtmlOutputFromFile('Email1').getContent();
  var recipient=e.response.getRespondentEmail();
  if(recipient!==undefined){
    MailApp.sendEmail({
      to:recipient,
      subject: 'Thank you. Please answer another one',
      htmlBody: htmlBody,
    })
  }
}

And the following email body:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <p>Thank you for filling the survey</p> 
    <p>Now fill another one. Some answers will be pre-filled based on your past responses<p> 
    <p>To continue click this <a href="https://docs.google.com/forms/d/e/1FAIpQLSfqYWf-V0Jrwh8ld2AjuHtskuEHr1CfQB3_wrLS7grzZ_EajQ/viewform?usp=pp_url&entry.786833434=<?= recipient ?>">Link</a></p>
  </body>
</html>

What am I doing wrong in this place that it does not retrieve the recipient variable from Code.gs but simply pre-fills the text "" in my second survey?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since the htmlBody is a string you can replace any text fragments with another text fragments, with string.replace() method.

Say you can make {RECEPIENT} in the html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <p>Thank you for filling the survey</p> 
    <p>Now fill another one. Some answers will be pre-filled based on your past responses<p> 
    <p>To continue click this <a href="https://docs.google.com/forms/d/e/1FAIpQLSfqYWf-V0Jrwh8ld2AjuHtskuEHr1CfQB3_wrLS7grzZ_EajQ/viewform?usp=pp_url&entry.786833434=<?={RECEPIENT}?>">Link</a></p>
  </body>
</html>

And then replace the text {RECEPIENT} it with recepient value in the script:

function confirmationEmail1(e) {
  
  var htmlBody= HtmlService.createHtmlOutputFromFile('Email1').getContent();
  var recipient=e.response.getRespondentEmail();
  if(recipient!==undefined){

    htmlBody = htmlBody.replace('{RECEPIENT}', recipient); // <--- here

    MailApp.sendEmail({
      to:recipient,
      subject: 'Thank you. Please answer another one',
      htmlBody: htmlBody,
    })
  }
}
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