This question already has an answer here:
Custom Functions with add-ons?
(1 answer)
Closed 1 year ago.
I am developing an add-on with custom functions. This also includes a sidebar.
When I test the addon, I do the authorizations and the sidebar functions as it should.
I am unable, however, to use the custom functions - they just don't appear when I start typing. I know they should work ok, since I prepared them in a bounded script originally and they were fine there. Then copy & paste to the standalone script, but no joy.
There are 3 OAuth scopes required by the script:
https://mail.google.com/
https://www.googleapis.com/auth/script.container.ui
https://www.googleapis.com/auth/spreadsheets
I then updated the appsscript.json file to include the scopes above, as suggested here:
Google Setting Scopes
I'm assuming this has something to do with authorizations. What should I be looking for? Any suggestions please?
I think you are experiencing the following issue, reported in Issue Tracker some time ago:
Issue #36763437. "Test as add-on" from standalone project to Google Sheets doesn't link custom functions
Custom functions don't seem to work when the add-on is being tested with Test as add-on. Crucially, this problem only seems to show up while in test mode: when the add-on is published, custom functions do show up.
Anyone you wants to keep track of this can click the star on the top left in the referenced page.
In any case, since the rest of the add-on actions seem to be working correctly, most probably the custom functions will work after the add-on is published. I understand, though, that not being able to test the add-on before publishing can be frustrating.
Related
I made an Apps Script for Google Sheets and published it as an editor Add-on for my company domain. Its one custom function and when I did an individual install for myself it works fine. And when anyone else in the org does an individual install it works fine. However when installing it for the whole company via Admin Console, the Add-on doesn't work and gives the following error unknown function. So I want to know what am I missing that is preventing this Add-on from working.
So after like 5 hours of not understanding what's going and not being able to find the solution. I figured it out. In the spreadsheet I had to go to Add-Ons -> Manage Add-Ons and on the Add-On I made there were the 3 vertical dots (options) and right clicking reveals a panel that says "Use in this document". Though a minor inconvenience - every time someone in the org creates a new spreadsheet and wants to use functions from the plug-in, they will have to do just that. Hope this helps.
I was trying to publish a new version of an Add-on that was already created, but when I tried to publish it, I can see the menus, sub-menus and I can execute the Add-On Picture 1. The problem is that the other users -who before were able to execute the Add-On- now they don't see the sub-menus and obviously they can't execute the Add-On Picture 2.
I Googled a little bit and I was investigating about this, so I found that there is a method called AuthMode.NONE and AuthMode.LIMITED, I know the differences between them but I don't know how Google Scripts classify the Add-Ons and how to force change the AuthMode to LIMITED, or maybe you can give me another solution that can help.
BTW: I already checked if the Add-On is activated for my document and yes it is, I mean that i have the option: Add-Ons --> Manage Add-Ons --> [my addon] --> Manage --> Use in this document checked.
PD: I tried uninstalling and installing the Add-On, publishing and re-publishing new versions, I tried a lot of things but no solutions.
Thanks in advance!
This read on Authorization modes may help:
If an add-on is installed for a user but not enabled in the current
document, onOpen(e) runs in AuthMode.NONE; if the add-on is enabled in
the current document, onOpen(e) runs in AuthMode.LIMITED. If the
add-on is both installed and enabled, the enabled state takes
precedence, since LIMITED allows access to more Apps Script services.
Note that only published add-ons can be in AuthMode.NONE; scripts that
are bound to a document, including add-ons in development, always run
onOpen(e) in AuthMode.LIMITED. You can, however, test a script as an
add-on to verify that an add-on under development will behave as
intended in either AuthMode.
Check this SO thread for additional reference.
I have a few questions relating to publishing an add-on for Google Sheets.
I have a script right now set up with an on load trigger to run the script. Is it possible to have my script run the same way if it's published as an add-on? If not, I guess I can probably have the user click some sort of menu option to run it (which calls a specific function in my script)?
If I publish the script, can users see the code? The problem I have right now is that the script I'm using connects to an API that uses an API key to limit user requests. The key is meant to be private, and for now it's fine that I just have it in the code since I'm only using it privately. I don't have a way to hide the API key from the users if the code is public though, so it would really be a problem if it was public.
If you publish the Google Script as a web app or as an add-on, others cannot see the source code of the script.
"I have a script right now set up with an on load trigger to run the script."
If this means that you are trying to do anything apart from create a custom menu in the onOpen() it could fail as it may not have the authorisation to run; you are limited to what you can do in onOpen() in an add-on. Take a look at the add-on authorisation cycle.
The user can't see your add-on code. However if you were planning to open source your code at any point you can store private things like API keys using the Properties Service that can be manually set in the script editor (File>Project Properties>Script Properties) or by running a bit of code that you then delete.
Answer to question 1:
Yes, you can use the onOpen(e) simple trigger as outlined in the documentation.
(https://developers.google.com/apps-script/guides/triggers/
Answer to question 2:
As Amit Agarwal mentioned in their answer, the code for a published add-on will be private. Users will not be able to see your API key.
I have a Google Sheets document with a bunch of script attached. I view and edit that script using Tools > Script Editor. This script also adds a new menu to the toolbar using the onOpen function.
If I share the document with a colleague, she sees the new menu and can run scripts in that menu, but Tools > Script Editor is disabled for her.
I'd like anyone with access to the document to also see the script. Do I need to create an add-on or something instead?
As documented in Google reference documentation, document bounded scripts inherit the sharing properties from their container.
(A few years ago it was not the case but even very old documents have all been updated).
If the behavior you describe can be repeatedly reproduced then you are most probably facing a bug and should report it to the issue tracker.
In the mean time try to make a copy of it and share it with the same user to see what happens.
A similar issue occured to me a while ago and unsharing/resharing the doc solved the issue. Worth trying...
I've made a simple script in Google Apps Script. The script builds forms based on a spreadsheet, the script itself is part of the spreadsheet. It adds a menu item. People would like to use it. They are non-technical people, so I would like to make the installation of my script as easy as possible. With 'installation' I mean a way to 'import' my script into their spreadsheet and automatically set up the needed triggers so the menu item becomes visible. It should be possible for anyone to install it.
I've been thinking of the following solutions:
Publishing as an add-on: my script wouldn't qualify, and even then I can't wait for Google's approval.
Copy-paste. I don't like this, it's way too complicated.
I've looked at this question: https://stackoverflow.com/questions/5334751/how-do-i-share-a-script-i-wrote-with-my-co-workers-on-the-same-google-apps-accou, but the people wanting to install it are not on the same domain in my case. The question is also 3 years old.
EDIT: As it turns out, there doesn't seem to be a solution. I've filed a feature request here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=4122&thanks=4122&ts=1403949074
If your Google Account administrator allows you, you can share scripts/spreadsheets outside your organisation either by sharing directly with another person with a Google Account (Gmail or Google Apps) or by making it public (share with a link or published online).
https://support.google.com/drive/answer/2494822?hl=en
Keep in mind that if you use the Script Properties to store values, each time someone uses the shared script it will overwrite the values. In a shared context it is best to use User Properties instead. This way each user can store their own values.
https://developers.google.com/apps-script/guides/properties
There is no way to import a script in an existing spreadsheet , the "normal" workflow is , in a way, the reverse process, that's to say create a sheet from an existing template that already has the script in it and start to work with that copy.
From your description I'm not sure this method could be useable but I'm afraid there is no other way if you want people who will be using it should not go into the script editor at all.
There would be a couple of functions to write that should run at install time and would create the triggers (if needed) and trigger the authorization process.
I made such a SS some time ago that needed authorizations and I added an "install" menu that made its use quite simple (example here on a friendly hosting site).
I know this is probably not the answer you were expecting but it was definitely too long to fit in a comment anyway.