I mean, when I run it normally, it works just fine!
This is an interesting problem I came across recently when reviewing one of my Google add-ons.
The issue was that when I ran my Google Apps Script add-on code normally – in my case, connected to a Google Sheet – the add-on would appear just fine in my add-on menu. However, when I tested the script as an add-on ( run >>> Test as add-on…), as installed for current user but not enabled, my app would not appear in the add-on menu.
If I were to publish this app in this condition (and I may have…eep!), the user would be able to see my add-on in the add-on menu but not be able to access the link to run the app’s function without going into Add-ons >>> Manage add-ons… then click on Manage >>> Use this add-on. The user would have to do this each time they want to apply my add-on to a new Google doc for the first time. Not a good user experience.
The reason is that the first time the app is run in a new document, the Authorization Mode is set to none:
When the user opens the document for the first time, the onOpen(e) trigger function is loaded along with any global variables that are in the script.
This is what Google Apps Script has to say about this:
So the problem was that one of my Global Variables did not abide by the scope of AuthMode.NONE.
How about we look at some example code to see how to identify the problem and work towards a solution.
Let’s say you want to print out a list of expenditures by department and you want each department to start on a new page. You’ll also want to keep the same header for each page.
You might want to export a list of grades by class number. You sort the grades by class and then export the list with each class starting on a new page with a header and footer.
Sections to Sheets can help you achieve this quickly by creating a new Google Spreadsheet and separating each selection and putting it into a new Sheet(tab) with or without headers and footer. This will enable you to quickly export or print your sheets.
Spacer is a Free Google Add-On that creates row spaces by column categories.
I use it as an academic administrator to create a space or two at the end of each class section to create a visual break between sections. This makes it easier for my staff to quickly identify class sections.