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

159
Visualizações
How to run google app script at exact time?

Currently, I want to run my google app script at exact time. I have already do some reading about this problem and I decide to follow the solution in this post It's possible run Google Sheets script Exact Time Everyday?.

However, every time the time trigger only work only once. It will display error for the second time trigger. I google about this problem and most of them state that is google v8 bug.( https://issuetracker.google.com/issues/150756612).

So, I'm decide to downgrade my code to ES5 since that is the only solution from the post( https://issuetracker.google.com/issues/150756612). But, I'm facing a problem about changing the spread operator(...) to ES5

Here is my code:

function runTrigger(hours,minutes) {
  
  var today_D=new Date();
  var year=today_D.getFullYear();
  var month=today_D.getMonth();
  var day=today_D.getDate();
  
  day=day+1; 
  
  var pars=[year,month,day,hours,minutes];
  
  var schedule_date=new Date(...pars);
  var hours_reamain=Math.abs(schedule_date - today_D)/36e5;
  
  ScriptApp.newTrigger("testFunction")
   .timeBased()
   .after(hours_reamain*60*60*1000)
   .create()  
}

function deleteTrigger() {
  var triggers=ScriptApp.getProjectTriggers();
  
  var ssId="1d5P4ohgSLtOzuInxq1IYQUsB4GybeYhth5Gj21RI3rA";
  var ss=SpreadsheetApp.openById(ssId);
  
  for(var i=0 ; i< triggers.length ; i++) {
    ss.appendRow([new Date() ,JSON.stringify(triggers[i]), JSON.stringify(triggers[i].getHandlerFunction()) , JSON.stringify(triggers[i].getEventType()) , JSON.stringify(triggers[i].getTriggerSource())])
    if(triggers[i].getHandlerFunction() === "testFunction") {
      ScriptApp.deleteTrigger(triggers[i]);
    }
  }
}

function setTrigger() { 
    deleteTrigger();
    runTrigger(1,35);
}

function testFunction() {
  //some code at here
  setTrigger();
}

Can anybody teach me how can I change the ...(spread operator) to ES5

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

0

I do not believe one can set a trigger to run at an exact time. My suggestion is to set the trigger to run the hour before the time you would like it to fire off, then, have you function run a loop checking for the exact time, perhaps run every minute.

about 4 years ago · Juan Pablo Isaza Relatório

0

What I'm doing so far is throwing a function that will set the trigger to the exact time based on the current time. I make sure the previous trigger is deleted and create it again.

function actionAtExactHour() {
  var f = 'myFunction'
  ScriptApp.getProjectTriggers().filter(trigger => trigger.getHandlerFunction() == f).forEach(t => ScriptApp.deleteTrigger(t))
  var d = new Date();
  ScriptApp.newTrigger(f)
    .timeBased()
    .after((60 - d.getMinutes()) * 60 * 1000)
    .create()
}
function myFunction(){
  SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange('A1').setValue(new Date())
}

However, I can't put a trigger on actionAtExactHour to e.g. fire the trigger daily and have myFunction run every day at the exact time...google will disable that trigger. To do this, I need to run actionAtExactHour myself a few minutes before the exact time I want

about 4 years ago · Juan Pablo Isaza Relatório

0

It's a javascript Date() constructor

 var schedule_date=new Date(year,month,day,hours,minutes);

Date() constructor

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