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

244
Visualizações
Google Apps Script trigger function runs twice

I have the following trigger setTrigger() set for when a Google Form is submitted. For testing purposes I created a simple function triggerFunction() that creates a .txt file in my Google Drive.

function setTrigger() {
  ScriptApp.newTrigger('triggerFunction')
  .forForm("formId")
  .onFormSubmit()
  .create();
}

function triggerFunction() {
  let folderId = [folderId];
  let blob = ['This is my blob'];
  DriveApp.getFolderById(folderId).createFile('file.txt',blob);
}

Now when I run the triggerFunction() manually it acts normally. It creates a file.txt in my folder. But when I submit a form on my Google form with formId it creates two separate file.txt files! How do I keep the trigger from running the function twice?!

I have tried the following but it still runs the function twice.

function setTrigger() {
  if (ScriptApp.getProjectTriggers().filter(t => t.getHandlerFunction() == "triggerFunction").length == 0) {
    ScriptApp.newTrigger('triggerFunction').forForm("formId").onFormSubmit().create();
  }
}
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