I have trouble with a time based trigger, which installs another time based trigger after work. I use this concept to split the work. Unfortunately the installed trigger never runs, but it is created.
The following code illustrates the concept:
function start() {
installTrigger();
}
function installTrigger(){
deleteClockBasedTriggers();
ScriptApp.newTrigger("sendMail").timeBased().after(5000).create();
}
function deleteClockBasedTriggers(){
var projectTriggers = ScriptApp.getProjectTriggers();
for(var i=0; i<projectTriggers.length; i++){
if(projectTriggers[i].getEventType() == ScriptApp.EventType.CLOCK){
ScriptApp.deleteTrigger(projectTriggers[i]);
}
}
}
function sendMail(){
var email = "[email protected]";
MailApp.sendEmail(email, "TriggerMail", "hello");
installTrigger();
}