I have an Google sheet add-on that uses a clock based trigger to make an api call to Google My Business API with a function called uploadPosts().
The User can set the trigger via the addon's menu like this:
function createTrigger() {
try{
deleteTriggers();
let ss = SpreadsheetApp.getActiveSpreadsheet();
let configTab = ss.getSheetByName('CONFIG');
let hour = configTab.getRange('A3').getValue();
let hourVal = hour.toString().split(" - ")[0].trim();
ScriptApp.newTrigger('uploadPosts')
.timeBased()
.atHour(hourVal)
.nearMinute(0)
.everyDays(1)
.create();
}
catch(err) {
console.log(err);
if (err.message === "Cannot read property 'getRange' of null"){
Browser.msgBox("???? Woa there! You must run Initial Setup, before turning on Auto-Posting! ???? ");
}
}
}
function deleteTriggers () {
try{
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
ScriptApp.deleteTrigger(triggers[i]);
}
}
catch(err) {
if (err.message === "Cannot read property 'getRange' of null"){
Browser.msgBox("???? Woa there! You must run Initial Setup, before turning off Auto-Posting! ???? ");
}
}
}
The triggers work fine for anyone who is an editor of the Add-on, but does not set a functioning trigger for add-on users. When they go to https://script.google.com/home/triggers they see a row with a "-" set for both the project name and function name.
What do I need to change in order for a clock based trigger to work for add-on users?
hourVal
? Does the uploadPost function exists (it was not included in the question)? – Rubén