我想以编程方式确定触发器是否已成功创建,但即使是不成功的触发器也会显示一个唯一的ID,而且似乎已创建。
//this will show 0
var triggers = ScriptApp.getProjectTriggers();
showAlert(triggers.length); //define showAlert
var dt = new Date(2015,03,03,20,10) // create past date or feb 31
//Month index starts from 0 i.e. Jan =0,Feb=1... So on
var ret = ScriptApp.newTrigger('myFunction').timeBased().at(dt).create()
showAlert(ret.getUniqueId()); //will display ID for sure
//this will show 1
var triggers = ScriptApp.getProjectTriggers();
showAlert(triggers.length); //define showAlert
但实际上没有创建触发器
答案 0 :(得分:1)
您最好的选择是检查输入的日期是否已过?并且只有在没有通过时才设置触发器。
var dt = new Date(2015,03,03,20,10) // create past date or feb 31
//Month index starts from 0 i.e. Jan =0,Feb=1... So on
if( dt > new Date()){ //new Date() gives current date
var ret = ScriptApp.newTrigger('myFunction').timeBased().at(dt).create()
}
希望有所帮助!