I have (amongst others) the following four functions.
fallback()
newSubmission()
installSubmissionTrigger()
uninstallSubmissionTrigger()
I have a trigger that:
fallback()
that posts something to the Spreadsheet for review.fallback
calls installSubmissionTrigger()
.installSubmissionTrigger
creates a time-based trigger running every minute.newSubmission()
.newSubmission
does something I want and calls uninstallSubmissionTrigger()
.uninstallSubmissionTrigger
removes the time-based trigger.All of this works fine using Rhino but when I enable V8 the time-based trigger becomes disabled for unknown reasons when it is supposed to run.
Also when using V8, if I run installSubmissionTrigger()
manually, the trigger does fire.
If I run fallback()
manually, the trigger also does fire.
What could be the unknown reason the trigger becomes disabled?
function fallback(event) {
...
installSubmissionTrigger();
...
}
function newSubmission() {
...
uninstallSubmissionTrigger();
...
}
function installSubmissionTrigger() {
var properties = PropertiesService.getScriptProperties();
if(!properties.getProperty("triggerID")) {
var trigger = ScriptApp.newTrigger('newSubmission').timeBased().everyMinutes(1).create();
properties.setProperty("triggerID", trigger.getUniqueId());
Logger.log("Creating newSubmission trigger: " + trigger.getUniqueId());
}
}
function uninstallSubmissionTrigger() {
var properties = PropertiesService.getScriptProperties();
properties.deleteProperty("triggerID");
// Loop over all triggers.
var allTriggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < allTriggers.length; i++) {
// If the current trigger is the correct one, delete it.
if (allTriggers[i].getHandlerFunction() === 'newSubmission') {
ScriptApp.deleteTrigger(allTriggers[i]);
}
}
}
Use-case example:
This issue you're having has been reported and it's related with V8 runtime [1]. You could work with DEPRECATED_ES5
runtime version which is working as expected.