2
votes

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.

enter image description here

What do I need to change in order for a clock based trigger to work for add-on users?

1
What is the value of CONFIG!A3? What value is being assigned to hourVal? Does the uploadPost function exists (it was not included in the question)?Rubén
The value is 4 - 5 ( AM ). The hourVal variable then turns that into 4. Yes the upLoadPosts function exists. It is in a different place in the apps script project.Noah Learner
The add-on builds the CONFIG sheet for the user as part of initial setup. The uploadPosts function is how the add-on uploads posts to the Google My Business api.Noah Learner
Hello, do the triggers disappear after some time? Or is it immediate? Does this happen with other Add-ons?Jescanellas
the triggers don't seem to disappear. I set them yesterday and they are still in place.Noah Learner

1 Answers

0
votes

The solution to this issue was twofold.

  1. The project used the newer V8 runtime. There were tons of issues in the apps script google groups re: the new runtime and time based triggers for add-ons.

I Modified all functions to revert to es5 syntax and then reverted to the old runtime.

  1. I needed to add a sensitive scope: https://www.googleapis.com/auth/script.scriptapp

After I got approved by Google and reverting runtimes, my triggers worked as anticipated.