Did Google Break Something (on open trigger)?

776 views
Skip to first unread message

Christopher Webster

unread,
Jan 21, 2020, 12:50:15 PM1/21/20
to google-apps-sc...@googlegroups.com
I have an "on open" trigger on a spreadsheet script that opens a menu item.  This script has been running for years.  Today a user told me the menu item wasn't reappearing after several reloads.  I tried and had the same issue.  I was able to manually run the script to get the menu item created but not with the trigger.  I deleted the trigger and created a new one, still no luck.  Anyone else having these issues?

Alan Wells

unread,
Jan 21, 2020, 1:15:19 PM1/21/20
to Google Apps Script Community
There is an issue on the Issue Tracker


Issues can be searched with:


Click the star so it turns yellow in order to show that it affects you.

Christopher Webster

unread,
Jan 21, 2020, 1:20:58 PM1/21/20
to Google Apps Script Community
Thank you Alan. I starred it.  However, this issue dates back to April.  My script was running fine until now.  

Alan Wells

unread,
Jan 21, 2020, 1:23:02 PM1/21/20
to Google Apps Script Community
From my experience, if I have a global variable, and assign a value to that global variable in the global scope, it causes an error in the onOpen() simple trigger.  There have also been recent reports of the onInstall trigger failing to run.  You should put error handling into your function and use Stackdriver.

function onOpen() {
try{

 
//my code here



}catch(e){
  console
.log('Error: ' + e + '\nStack: ' + e.stack);//Log error to Stackdriver

}
}


You can navigate to Stackdriver from the code editor through the View menu.

Christopher Webster

unread,
Jan 21, 2020, 1:33:07 PM1/21/20
to Google Apps Script Community
I do have some global variables, but it seems strange they would just now be an issue when the code has not been touched for at least a year.

Stackdriver was the first thing I checked.  It appears the trigger is not firing at all, so the callback function is not even being run. 

Kim Nilsson

unread,
Jan 21, 2020, 1:45:48 PM1/21/20
to Google Apps Script Community
AJ, is that all that's need for logging to Stack, or is there a necessary guide somewhere one has to follow to set it up too?

Steve Webster

unread,
Jan 21, 2020, 1:51:28 PM1/21/20
to google-apps-sc...@googlegroups.com
Here are some thoughts that may help resolve.
1. Yes, Google does make improvements and changes like due diligence for a potential vulnerability. In other words, what worked for years may need code changes.
2. Your onOpen() should be onOpen(e).
3. Here is the current restrictions for automatically run simple triggers: 
4. When using "try/catch", in most cases, you can implement exponetial backoff (e.g. it sleeps and tries again). This is helpful just in case Google servers have hipcups :)

Kind Regards,

Steve Webster
SW gApps LLC, President 
Google Product Expert in: Google Apps Script, Drive, and Docs 
Google Vendor (2012-2013) || Google Apps Developer Blog Guest Blogger 
Add-ons: Text gBlaster and Remove Blank Rows


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/c15df7e3-40ac-4d1c-a85b-94ccdaaac6d1%40googlegroups.com.

Alan Wells

unread,
Jan 21, 2020, 1:52:16 PM1/21/20
to Google Apps Script Community
Triggers have a long history of silently failing.  People regularly report that triggers that worked for years, suddenly stop working with no warning.  We may not get a definitive answer from Google about what to do about it.
Does your user need to authorized the script from their account?  If so, they may have lost authorization, and need to re-authorize. But, they may need to revoke permissions first.   I have a button that users can click to revoke authorization so they don't need to navigate through their account.

Christopher Webster

unread,
Jan 21, 2020, 2:03:42 PM1/21/20
to google-apps-sc...@googlegroups.com
So I realize I should have been clearer about this from the beginning; the trigger is an installable trigger not a  simple trigger.  On the trigger page, it shows the trigger is not running at all, desipte the sheet being open and closed several times.  As you know installable triggers are run as the script owner.  In the past, I have had the issue where I need to reauthorize a permission,  That was not the issue this time. 

Alan Wells

unread,
Jan 21, 2020, 2:04:28 PM1/21/20
to Google Apps Script Community
It depends on what you want.  If it's "good enough" to see a simple log without setting up an associated GCP project with your Apps Script project, then you can view the logs through the Apps Script Dashboard "My Executions"


If you navigate through the code editor, then you'll be taken to My Executions for that project, and you can expand the row to see logs.  I don't want to create GCP projects for most of my scripts.  That would be totally unnecessary.  So, for simple troubleshooting, using  Apps Script Dashboard "My Executions" is "good enough" for that situation.

Christopher Webster

unread,
Jan 21, 2020, 5:11:47 PM1/21/20
to Google Apps Script Community
Alright, so it just started working again out of the blue.

Dimu Designs

unread,
Jan 21, 2020, 5:36:55 PM1/21/20
to Google Apps Script Community
I've noticed that whenever Google is making big changes behind the scenes all sorts of weird glitches crop up. Its akin to how "deja vu" is explained in the Matrix (movie). Maybe this bug is a result of the latest GSuite add-on update.

Christopher Webster

unread,
Jan 21, 2020, 5:38:23 PM1/21/20
to google-apps-sc...@googlegroups.com
I was thinking that too but wanted to know if others were having issues.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/MilRqcykS4Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a9bc05c4-b360-4fb5-b10a-a0a5f7447aad%40googlegroups.com.

Christopher Webster

unread,
Jan 21, 2020, 5:39:26 PM1/21/20
to Google Apps Script Community
I was thinking that too but wanted to know first if others were having issues

Kalianne L. Neumann

unread,
Jan 21, 2020, 7:51:06 PM1/21/20
to Google Apps Script Community
I'm jealous that your add-on is working. I think I'm running into the same issue with a new add-on that was going through the review process this week. When I test the add-on from my script, it functions properly; however, during review, I was informed that after install, the add-on doesn't load. 

I'm not sure what happened, but the add-on was somehow published today with this error, and it doesn't even open the menu after installing: Parts of Speech add-on.

I'm a novice with all of this - mostly working in trial and error off a script from another add-on someone else helped me publish. When I Run the OnOpen and OnInstall functions in the script, the following error comes in the highlighted line below: Cannot call DocumentApp.getUi() from this context. (line 12, file "PartsofSpeech")

function onOpen(e) {
  //  DocumentApp.getUi().createMenu("Parts of Speech")
  //  .addItem('Open Toolbar', 'showSidebar')
  //  .addToUi();
  DocumentApp.getUi().createAddonMenu().addItem('Open Toolbar', 'showSidebar').addItem('About', 'showAbout').addToUi();

}

Debugging the OnOpen function points to the same line of code; however, debugging the OnInstall function points to the above line of code as well as the one highlighted below:

function onInstall(e) {
  onOpen(e);
}

If anyone has any ideas about this, I would greatly appreciate hearing them. Also...if you want to look at any other lines of code that may be creating the error, just let me know. 

Thanks in advance for any assistance and for patience with my limited knowledge. :) 

Alan Wells

unread,
Jan 21, 2020, 9:04:47 PM1/21/20
to Google Apps Script Community
If your script is in a "stand alone" file, (not bound to a document - Form, Doc, Sheet) then the script won't be able to find a document to add a menu to when the code is run from the script editor.  Either the script needs to be bound to the Google Doc, or you can click the "Run" menu, and the "Test as add-on" menu item.  I usually only configure one document at a time.  I've had issues in the past with adding lots of documents to test the add-on from.
The problem with developing the add-on from a bound script, is that you'd probably want to publish from a stand alone file.  But then you'd need a way to transfer all your code from the bound project to the stand alone project.  And copying and pasting is a waste of time.

Kalianne L. Neumann

unread,
Jan 21, 2020, 9:24:27 PM1/21/20
to Google Apps Script Community
The script is bound to a document, and I went through publication through the bound script. The add-on functions perfectly fine when I test it via the "Test as add-on" menu in the bound script and any other documents I try it on; however, it wouldn't open for the reviewer, and now that it's published, the published version of the tool (Parts of Speech) will install but will not appear when you go to "Add-ons" in a Google Doc (see below - Parts of Speech should appear in this dropdown). 

Screen Shot 2020-01-21 at 8.20.38 PM.png



I went to manage add-ons, and the only option it gives me is Uninstall (see below). 

Screen Shot 2020-01-21 at 8.22.05 PM.png



With my other add-ons, including one I have published, the options I get are Uninstall, Use in this document, Help, and Report an issue (see below)

Screen Shot 2020-01-21 at 8.18.46 PM.png

Alan Wells

unread,
Jan 21, 2020, 9:38:33 PM1/21/20
to Google Apps Script Community
I installed your add-on, and can confirm that there is no add-on menu being created.  The original poster stated that their trigger is suddenly working again, with no indication of why.  So, I don't know if this is a temporary problem for you also, or there is something that you need to fix.  You could add error handling to your function, and see if it logs something to Stackdriver.  I always put the onOpen function in the default "Code" file and make sure that I don't name any files alphabetically before "Co"  I always put "onInstall" at the top of the "Code" file and "onOpen" directly under it, and then don't put anything else in that file.  And I never assign a value to a global variable in the global scope.  That's what works for me, whether it makes any sense or not.

Kalianne L. Neumann

unread,
Jan 22, 2020, 11:12:06 AM1/22/20
to Google Apps Script Community
I just tried what you suggested, and I'm not sure why it worked, but it did! Thank you!!

Alan Wells

unread,
Jan 22, 2020, 11:50:31 AM1/22/20
to Google Apps Script Community
Thank you for confirming that it worked.  What did you change from what you had before?

Kalianne L. Neumann

unread,
Jan 22, 2020, 11:56:13 AM1/22/20
to Google Apps Script Community
I only moved onInstall to the top of the code with onOpen directly under it. In my previously published add-on, it wasn't in this order and worked, so I'm not really sure why I needed to change it this time around; however, I appreciate the suggestion - SO MUCH! 

David Ho

unread,
Oct 27, 2022, 1:07:34 PM10/27/22
to Google Apps Script Community
I'll add my 2 cents to this.  I have two triggers from two Apps Scripts that run on some Sheets container.  All of this was working, and then now it's not.  I've deleted the triggers, recreated the project and scripts from the sheets container, and then re-authorized via OAuth consent screen.  Still not working.  The thing is, I have an exact duplicate of this project and sheet running for another client that DOES still work.  

I get that Google fixes and updates things that may break triggers that work for years, but this does NOT explain my case.  Why is one sheet / container with the same code / triggers not working and another one is working?  

David Ho

unread,
Oct 27, 2022, 1:11:36 PM10/27/22
to Google Apps Script Community
Holy hell, never mind.  After an hour long, all of the event triggers activated at once and I see them all now in the execution log.  What the hell???  More and more I'm realizing I can't rely on Google for creating and hosting my programs.

virendra kumar

unread,
Jan 7, 2024, 5:23:08 AMJan 7
to Google Apps Script Community
Hi, 
I aom deplouying google slides Addon , I got this email

Menu - Menu options not shown after App is installed. Please ensure that the add-on correctly uses onInstall() and onOpen() to populate its menu. The menu items populate when the add-on is first installed and when a different file is opened.

Could you suggest, whait I am doing wornng?

Afaan Naqvi

unread,
Feb 21, 2024, 4:15:45 AMFeb 21
to Google Apps Script Community
I am in the same boat as several people in this thread.
Mine is a Sheets Editor AddOn and I was using the "Installed and Enabled" option when testing,  and my onOpen(e) and onInstall(e) functions were working just fine for months during these tests.

Then, when I finally passed the OAuth Verification and CASA Scan steps and submitted my App for the Google Workspace Marketplace verification, I got the same message as Virendra above, and now magically the triggers do not fire even in my tests.
I even started a new Apps Script project with just a single code file as follows:

function onOpen(e){
Logger.log("In onOpen")
Logger.log(e.authMode)

SpreadsheetApp.getUi()
.createAddonMenu()
.addItem('README', 'readmeSidebar')
}

function onInstall(e) {
Logger.log("In onInstall")
onOpen(e);
}

And testing this (both with "Installed and Enabled" and only "Installed" options) results in no extensions menu being generated, and no record of either simple trigger running, let alone any logged errors that I can review and debug.
I just hope this is Google temporarily mucking about in the background and that it will magically start working again in a day or 2.

Any thoughts or feedback greatly appreciated.

Afaan Naqvi

unread,
Feb 22, 2024, 9:13:42 AMFeb 22
to Google Apps Script Community
Ok this was not Google after all.
I was selecting the radio button for my test in the testing dialogue and then clicking the SHEET_NAME in the same row as the radio button, instead of the "Execute" button at the very top of the testing dialogue.
My app is approved and should be on the Marketplace later today I am told.

Thanks for the help and guidance.
Reply all
Reply to author
Forward
0 new messages