GAS Add-on, onOpen function running continuously?

Viewed 38

I have two Google Sheets add-ons that I have written for private use by users in my domain. Both add-ons use the onOpen function to generate a menu in Sheets. Both are written with the standard format provided in the Google Developers documentation. An example of the code for the menu is below. Note that no triggers are installed in any portion of my script.

function onOpen(e) {
  var ui = SpreadsheetApp.getUi();
  ui.createAddonMenu()
    .addItem('1️⃣ Authorize', 'authFunction')
    .addItem('2️⃣ Format Sheet', 'ResetDataHTML')
    .addSubMenu(ui.createMenu('3️⃣ Type & Clean Up')
      .addItem('️ Set Trip type', 'setTripType')
      .addItem('️ Remove & Set Count', 'deleteNoTrans'))
    .addItem('4️⃣  Email to Transportation', 'emailSheetNote')
  .addToUi();
  return;
}

The add-ons both function properly. The "problem" I am noticing is when viewing the Execution Logs in the new IDE. For one add-on the onOpen function is constantly running/completing at an interval of about 1-3 seconds. The other add-on seems to run the onOpen function at intervals of about 20-30 minutes. My question is, "why would these add-ons continue to run the onOpen function? Am I noticing normal behavior or is this abnormal? (I have not noticed this behavior with any other script that uses the onOpen function.)

Thank you to anyone that might have some insight as to my issue.

1 Answers

Yes. Every time you or the other users visit or refresh the sheet, it does trigger the onOpen trigger thus possibly showing in your execution logs multiple times. Don't worry about it as that is entirely normal.

Related