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

173
Vistas
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
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