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

272
Views
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 answers
Answer question

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 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!