LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Monday, May 6, 2019

1分おきのトリガーを作って5分経ったらトリガーを全部消す


トリガーの練習用に書いたコード



コード.gs
function createTriggers1Minutes() {
  var trigger = ScriptApp.newTrigger('myFunction');
  trigger.timeBased()
  .everyMinutes(1)
  .create();
  addDeleteTrigger();
}  

function myFunction() {
  console.log("log: " + new Date()); 
}

function addDeleteTrigger() {
 var trigger = ScriptApp.newTrigger('deleteTrigger')
 trigger.timeBased()
 .everyMinutes(5)
 .create();
}

function deleteTrigger() {
  var allTriggers = ScriptApp.getProjectTriggers();
  for (var i = 0; i < allTriggers.length; i++) {
    ScriptApp.deleteTrigger(allTriggers[i]);
  }
}


参考

timeBased()
https://developers.google.com/apps-script/reference/script/trigger-builder#timeBased()

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...