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

175
Views
How to run a function based on an answer

I am trying to figure out how to make a script to run a function based on an answer provided, at the moment my script creates and populates a word doc with answers provided from a google form. I want to streamline it so that I can use one google form to create different documents based on an answer provided rather than creating multiple google forms. I am very new to JavaScript and I am pretty sure I need an if statement at the beginning of everything, but I don't know what I should write or where it should go. This is my script:

function onOpen()  {
  const ui = SpreadsheetApp.getUi();
  const menu = ui.createMenu('AutoFill Docs');
  menu.addItem('Create New Docs', 'createNewGoogleDocs');
  menu.addToUi();

}

function createNewGoogleDocs(){

  const googleDocTemplate = DriveApp.getFileById('google file goes here');
  const destinationFolder = DriveApp.getFolderById('google folder goes here');
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Response');
  const rows = sheet.getDataRange().getValues();

rows.forEach(function(row,index) {
  if (index === 0) return;
  if (row[9]) return;
  const copy = googleDocTemplate.makeCopy(`${row[5]} document name goes here`, destinationFolder);
  const doc = DocumentApp.openById(copy.getId())
  const body = doc.getBody();

  body.replaceText('{{Name}}', row[5]);
  body.replaceText('{{To}}', row[6]);
  body.replaceText('{{Items}}', row[7]);
  body.replaceText('{{Reasoning}}', row[8])
  body.replaceText('{{Submitter}}', row[1]);
  body.replaceText('{{Role}}', row[2]);
  body.replaceText('{{Time}}', row[3]);
  body.replaceText('{{Discord}}', row[4]);



  doc.saveAndClose();
  const url = doc.getUrl();
  sheet.getRange(index + 1, 10).setValue(url)




})




}
about 4 years ago · Juan Pablo Isaza
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!