I am trying to programmatically add a trigger to a Google Apps Script - I have a function main()
I want to schedule, which wraps another timebased trigger call using the ScriptApp.newTrigger().create()
call like this
function main(){
/*
* do stuff
*/
doScriptCallback();
}
function doScriptCallback(){
if(CONFIG.CALLBACK_SCRIPT_NAME != ''){
try {
ScriptApp.newTrigger(CONFIG.CALLBACK_SCRIPT_NAME)
.timeBased()
.after(5000)
.create()
Logger.log('Scheduled ' + CONFIG.CALLBACK_SCRIPT_NAME);
} catch(e) {
Logger.log(e);
}
}
}
running main()
from the editor correctly runs doScriptCallback()
and schedules the function in CONFIG.CALLBACK_SCRIPT_NAME
But if I schedule main()
then the doScriptCallback
only logs the message, but the function does not run.
Is this a restriction in Google Apps script?
CONFIG.CALLBACK_SCRIPT_NAME
asmain
and this seems to work without issue. Where are you getting the value to insert into the trigger as the function name? – Rafa GuillermoCONFIG.CALLBACK_SCRIPT_NAME
; is this inside themain() { //do stuff }
? – Rafa Guillermo