I have (amongst others) the following four functions.
fallback()
newSubmission()
installSubmissionTrigger()
uninstallSubmissionTrigger()
I have a trigger that:
- Runs on form submission.
- Calls
fallback()
that posts something to the Spreadsheet for review.
fallback
calls installSubmissionTrigger()
.
installSubmissionTrigger
creates a time-based trigger running every minute.
- The trigger calls
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:
- A customer submits a request for a pricing offer for new door.
- Then they also submit a request for a pricing offer an extension to their house.
- This door will most likely be part of the extension so ideally we would send this request to a company that deals with house extensions as well as doors.
- But if the door request was processed immediately it might have been sent to a specialist that exclusively deals with doors.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…