一部のシートを更新するには、Google スプレッドシートに多くのトリガーを設定する必要があります。
面倒な作業を避けるために、タスクの機能 (バッチ処理など) で、必要な他のトリガーをプログラムで設定する 1 つのトリガーを手動で設定しました。
さて、これらのトリガーを作成するために呼び出される私の関数は次のとおりです
function createTriggers(sheet, hour){
var nbTrigger = sheet.getLastColumn() * sheet.getLastRow() / 1100 + 1 ;
var buffHour = new Date().getHours();
var min = new Date().getMinutes()+10;
if(min >=60){
min = min % 60;
buffHour++;
if(buffHour>=24){
buffHour = buffHour % 24;
}
}
//Browser.msgBox(buffHour+"h"+min);
var ok = false;
var cpt = 0;
do {
try {
ScriptApp.newTrigger("triggered").timeBased().atHour(new Date().getHours()).nearMinute(Math.abs(1)).everyDays(1).create();
ok = true;
} catch(e) {
Logger.log(e);
Utilities.sleep(1000);
cpt++;
}
}while(!ok && cpt<10);
if(cpt>10){
throw "Was unable to create a trigger...";
}
for(var i = 0; i<nbTrigger; i++){
ok = false;
cpt = 0;
do {
try {
var trigger = ScriptApp.newTrigger("update").timeBased().atHour(buffHour).nearMinute(Math.abs(min)).everyDays(1).create();
ok = true;
} catch(e) {
Logger.log(e);
Utilities.sleep(1000);
cpt++;
}
} while(!ok && cpt<10);
if(cpt>10){
throw "Was unable to create a trigger...";
}
Utilities.sleep(10000);
min +=7;
if(min >= 60){
buffHour++;
min = 0;
if(buffHour == 24){
buffHour = 0;
}
}
}
}
そのため、トリガーの作成を try catch ブロックに入れる必要があります。
Wed May 09 13:36:41 PDT 2012 INFO: Exception: Invalid value -2 for field MINUTE, should be between [Range:0, 59]
Wed May 09 13:36:42 PDT 2012 INFO: Exception: Invalid value -8 for field MINUTE, should be between [Range:0, 59]
Wed May 09 13:36:43 PDT 2012 INFO: Exception: Invalid value -7 for field MINUTE, should be between [Range:0, 59]
Wed May 09 13:36:44 PDT 2012 INFO: Exception: Invalid value -7 for field MINUTE, should be between [Range:0, 59]
それはどこから来たのですか ??なぜ毎回ではないのですか?? これを避けるにはどうすればよいですか?
ありがとう !