Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda