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

489
Visualizações
Google Apps Script - script runs twice?

I'm fairly new to Google Apps Script and I may be missing something, but I'm trying to make a very basic script for testing purposes and literally everything I write runs twice. Absolutely no idea why. Can someone point me in the right direction for some reading I can do on this?

Right now, I'm just working with the Calendar API and getting the names of my calendars, but they always print twice. Here is the code:

function myFunction() {
  let calendars = CalendarApp.getAllCalendars();
  let haveCalendar = false;
  for(i=0;i<calendars.length;i++){
    if (calendars[i].getTitle() == "Holidays"){
      Logger.log(calendars[i].getTitle());
      haveCalendar = true;
    } else if (haveCalendar == true || calendars[i].getTitle() != "Holidays"){
      Logger.log("already have calendar");
    }
  }
}

myFunction();

The current output for this is:

already have calendar
already have calendar
Holidays
already have calendar

already have calendar
already have calendar
Holidays
already have calendar

I'm completely baffled. Any help would be greatly appreciated. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I don't recall much from Google app but i think it's because you called the function twice

remove the last line

myFunction();

and I think it should be fine. Cause their example from google as well don't call the function again

about 4 years ago · Juan Pablo Isaza Relatório

0

Call from run button

function donothing(a = "one") {
  Logger.log(a);
}

donothing("two");

Execution log
9:06:36 PM  Notice  Execution started
9:06:36 PM  Info    two
9:06:36 PM  Info    one
9:06:37 PM  Notice  Execution completed
about 4 years ago · Juan Pablo Isaza Relatório
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