title: time based trigger to function that sets triggers fails intermittently
body: <p>I have a function (see below) that deletes and then resets 3 triggers programmatically based on times contained in a sheet that are calculated based on the GoogleClock() function, and that auto-increments each day to the next workday (using the WORKDAY() ) function and a range containing all holidays.  One of the three triggers it sets is a trigger to run itself again at the end of following workday, wherein the process restarts.</p>
  
  <p>This is working about 60% of the time, and failing the rest of the time.  No error email message is being generated, as far as I have seen.</p>
  
  <p>The function is below. The while loop is intended to ensure that the spreadsheet values are not in the midst of GoogleClock() recalculation when the script runs, which was my original suspicion for why it was failing.  Any suggestions?</p>
  
  <pre><code>function setCustomRunTriggers() {
    Utilities.sleep(5000);
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PushedSchoolHolidays");
    var nextMidnight = sheet.getRange('D3').getValue();
    var nextSeven = sheet.getRange('D4').getValue();
    var nextSevenOFive = sheet.getRange('D5').getValue();
    var type =  getType(nextMidnight);
    while (type!="Object") {
      nextMidnight = sheet.getRange('D3').getValue();
      nextSeven = sheet.getRange('D4').getValue();
      nextSevenOFive = sheet.getRange('D5').getValue();
      type =  getType(nextMidnight);
    }
    var triggers = ScriptApp.getScriptTriggers();
    for (var i = 0; i&lt;triggers.length; i++) {
      var eventType = triggers[i].getEventType();
      var triggerSource = triggers[i].getTriggerSource();
      var handlerFunction = triggers[i].getHandlerFunction();
      if ((handlerFunction=='functionA')&amp;&amp;(eventType=="CLOCK")&amp;&amp;(triggerSource=="CLOCK")) {
        ScriptApp.deleteTrigger(triggers[i]);
      }
      if ((handlerFunction=='functionB')&amp;&amp;(eventType=="CLOCK")&amp;&amp;(triggerSource=="CLOCK")) {
        ScriptApp.deleteTrigger(triggers[i]);
      }
       if ((handlerFunction=='setCustomRunTriggers')&amp;&amp;(eventType=="CLOCK")&amp;&amp;(triggerSource=="CLOCK")) {
        ScriptApp.deleteTrigger(triggers[i]);
      }
    }
    ScriptApp.newTrigger('functionA').timeBased().at(nextMidnight).create();
    ScriptApp.newTrigger('functionB').timeBased().at(nextSeven).create();
    ScriptApp.newTrigger('setCustomRunTriggers').timeBased().at(nextSevenOFive).create();
  }
  </code></pre>