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

279
Vistas
Pass var Value to another var For Use With body.replaceText

I'm working on a script that takes my Google Forms data and performs a replace function on a predetermined template Doc file using body.replaceText which is working fine. I've copied a truncated version of that below.

I can submit a form and it will replace the values of the template as designed but there are some multiple-choice (Yes or No) questions that are represented by checkboxes on the template Doc.

I've figured out how to Logger.log the checkboxes via unicode but how do I get var systemOperational.getValue = "yes" to assign a value to var systemOperationalYes using IF/Else?

Trying to have "If systemOperational value is Yes then systemOperationalYes = unicode \u2611 Else systemOperationalYes = unicode \u2610".

Pardon me if any of this sounds amateur. This is literally my first go at this.

  
  //e.values is an array of form values
  var timestamp = e.values[0];
  var emailAddress = e.values[1];
  var jobID = e.values[2];
  var storeName = e.values[3];
  var systemOperational = e.values[22];

if (systemOperational.getValue = "yes") {
  var systemOperationalYes = "\u2611";
  Logger.log("\u2611");
} else {
  var systemOperationalYes = "\u2610";
  Logger.log("\u2610");
  }
 
// Locat template file
var files = DriveApp.getFolderById("XXXXXXX").searchFiles('title contains "'+ jobID +'"');
while (files.hasNext()) {
  var file = files.next();
  Logger.log(file.getId());
}
  //file is the template file, and you get it by ID
  var templateFile = DriveApp.getFileById(file.getId());
 
  //We can make a copy of the template, name it, and optionally tell it what folder to live in
  //file.makeCopy will return a Google Drive file object
  var responseFolder = DriveApp.getFolderById("XXXXXXXXX");
  
  //Converts dateSigned var to MM-dd-yyyy for use in file name
  var convertedDate = new Date(dateSigned);
  Logger.log(convertedDate);
  var formatSignDate = Utilities.formatDate(convertedDate, "GMT-5", "MM-dd-yyyy");
  Logger.log(formatSignDate);

  var folder = responseFolder.createFolder(storeName + '-' + jobID + '-' + formatSignDate);
  var copy = templateFile.makeCopy(storeName + '-' + jobID + '-' + formatSignDate, folder);
 
  //Once we've got the new file created, we need to open it as a document by using its ID
  var doc = DocumentApp.openById(copy.getId());
 
  //Since everything we need to change is in the body, we need to get that
  var body = doc.getBody();
 
  //Then we call all of our replaceText methods
  body.replaceText('{{SYSOPY}}', systemOperationalYes);
 
  //Lastly we save and close the document to persist our changes
  doc.saveAndClose();
  
  // Convert temporary document to PDF
var pdf = DriveApp.getFileById(copy.getId()).getAs("application/pdf")
var url = DriveApp.getFolderById(folder.getId()).createFile(pdf);
 
 
// Delete temp file
//DriveApp.getFileById(templateFile.getId()).setTrashed(true);



}```
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

try it this way:

var timestamp = e.values[0];
var emailAddress = e.values[1];
var jobID = e.values[2];
var storeName = e.values[3];
var systemOperationalYes;

if (e.values[22] = "yes") {
  systemOperationalYes = "\u2611";
  Logger.log("\u2611");
} else {
  systemOperationalYes = "\u2610";
  Logger.log("\u2610");
}
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