Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda