Custom Functions with add-ons? - google-apps-script

I've been trying to create a Google Spreadsheet plugin from some existing Google App Scripts that I have, and one important part of this app script is Custom Functions.
Though the documentation for the add-ons doesn't indicate that this is supported, the documentation for Custom Functions does indicate that you can.
https://developers.google.com/apps-script/guides/sheets/functions
Through testing, I have not once been able to get Custom Functions exposed through a add-on. Does anyone know the secret sauce to get this to work?

Answer
According to Eric Koleda in [Code.gs - date_add_and_subtract]( https://github.com/google/google-apps-script-samples/blob/master/date_add_and_subtract/Code.gs) to make available the custom fuctions in an add-on it's required to include at least one add-on menu, but this is not working at this time on testing mode.
NOTE: The originally referred page was removed but the Date add and substract add-on sample code is available at https://github.com/googlesamples/apps-script/tree/master/sheets/dateAddAndSubtract.
The "solution" to test a custom function add-on is to publish the add-on privately so you could avoid the Google review of an untested add-on. Related Q&A: Publish an add-on privately
NOTES:
You have to create a Google Cloud Project, set OAuth Consent Screen, add the Google Workspaces Marketplace SDK, complete the configuration page, the listing page and to publish the add-on
Setting the OAuth Consent Screen for Internal Use requires to a Google Workspace Account
Setting the OAuth Consent Screen for External Use limited to test account only doesn't allow to publish the add-on to the GW Marketplace.
One scenario is to use different Google Cloud Projects for testing and production but use the same Google Apps Script project. Another scenario is to have two different Google Apps Script projects each one with their own Google Apps Project and someway copy the code from one to the other i.e. using Google Apps Script GitHub Assistant Chrome Extension, CLASP or the Google Apps Script API.
Remarks
There are a couple of related GAS issues, please star them:
"Test as add-on" from standalone project to Google Sheets doesn't link custom functions
After activating an add-on, custom functions get stuck Loading... until spreadsheet refresh

Related

Google Sheets Workspace Add-on versus Editor Add-on for custom functions

I have a published Editor Add-on for Google Sheets. It is deployed via the Sheets Add-on section within the App Configuration page of the Google Workplace Marketplace service on GCP.
I have been thinking about moving it to a Workspace Add-on in order to make use of the Card functionality. However, I haven't been able to confirm that the latter is actually able to use custom functions. For example, https://developers.google.com/apps-script/add-ons/concepts/types says:
Each Editor Add-on type (for example, Sheets add-ons) can have its own set of type-specific capabilities, restrictions, and special considerations. When building Editor Add-ons, it's important to understand these Editor-specific details
And going to the Sheets page, mentions custom functions. It also doesn't help that there seems to be no way to actually test the custom functions are working via either method of testing due to https://issuetracker.google.com/issues/36763437 without having a published Editor Add-on. So I haven't been able to confirm this way either.
Are Google Workspace Add-on a replacement to the current Editor Add-on? I.e. can I check/use the Google Workspace Add-on option and uncheck the Sheets Add-on? Or do I need to use both, the Workspace Add-on for the Card feature and Editor Add-on for custom functions?

User testing Google Docs addon

I've written a simple Google Docs addon and prior to publishing it, I would like to allow some friends to test. I managed to do that by sharing the project and having another account create his deployment and test but this is too cumbersome.
I looked around and apparently I needed a project in GCP. I opened a project, edited the OAuth Consent Screen, and assigned my script to that project. I also added test users under OAuth Consent Screen. How do I get those users to install this now and test?
Thanks
"Testing" is a very broad term, and could mean multiple things in this context.
If it's "try it out" then you can publish it privately to your Workspace domain as you don't need to go though the review (reference). Note though that this only works if you have the Workspace domain. This is usually used for internal tools in companies. Other than that, it has the same requirements as publicly publishing it with the exception of being reviewed by Google (see process overview).
If you want them to debug it, you'll have to use the "test deployment", as it has some more tools helping debug errors. You can have a project in a shared drive; this would remove the need to share it manually, but the deployment will have only a single account as its publisher (reference).
References and further reading
Publish an add-on (Apps Script guide)
Test an editor add-on (Apps Script guide)
Create and manage deployments (Apps Script guide)
Update and manage your published add-on (Apps Script guide)
About app review (Google Marketplace guide)

Google Add-on for sheets invalid scope

So following this tutorial I am attempting to extend by adding the add-on via the sidebar. [See the screen shot below] []2
But I am getting this error when attempting to add this auth scope.
Error: invalid_scope
Some requested scopes were invalid. {valid=
[https://www.googleapis.com/auth/gmail.addons.current.message.readonly,
https://www.googleapis.com/auth/script.locale, https://www.googleapis.com/auth/spreadsheets.readonly,
https://www.googleapis.com/auth/gmail.addons.current.action.compose,
https://www.googleapis.com/auth/calendar.addons.execute,
https://www.googleapis.com/auth/drive.addons.metadata.readonly,
https://www.googleapis.com/auth/calendar.readonly,
https://www.googleapis.com/auth/gmail.addons.execute], invalid=
[https://www.googleapis.com/auth/spreadsheets.addons.execute]}
My question is do I need this https://www.googleapis.com/auth/spreadsheets.addons.execute for sheets to see the homepage triggers in my manifest? If not what am I overlooking?
UPDATE
We now have support for Workspace Add-ons in Google Sheets, Google Docs and Google Slides (though it may not be available in all regions as yet)...Google Forms is not yet supported.
What you want to do is not possible as you can only create Editor Add-ons for Google Sheets not GSuite Add-ons.
There are distinct differences between the two.
GSuite Add-ons are currently only applicable to:
Gmail
Google Drive
Google Calendar
Editor Add-ons are currently only applicable to:
Google Sheets
Google Forms
Google Docs
Google Slides
See add-on types documentation for clarification.
Actually you're experiencing this issue because the feature hasn't rolled out yet to your account.
It appears this is a Google Workspace account so you need to navigate to https://admin.google.com/ac/accountsettings/preferences
And select "New Feature"
Then you must select "Rapid Release" and the new Google Workspace add-on feature will be enabled for you probably within 15 minutes but it can take up to 24 hours.
I was experiencing this same issue and once I added this it worked fine.
Also, there isn't an auth scope of https://www.googleapis.com/auth/spreadsheets.addons.execute
You need to simply add https://www.googleapis.com/auth/spreadsheets
and it will work perfectly. Good luck!

Publish an add-on from Standalone Google Apps script

I have developed a google sheet addon, I had succefully published that add-on from Google sheet bound script ie from tools->Script editor.
But If I made direct google apps script project(standalone project),I am unable to publish it,And a notification is popped up.
I research that I need it to setup it from google console,to publish standalone google app script to add-on ,But I don't found exact options to proceed.
The instruction is a very confusing for a first timer. Google keeps redirecting you to the page describing publishing editor addons, but what you really need is the page describing how to create a project on cloud platform.
https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project
Steps:
Create Project and get Project Number using instructions from link above
Go to you script. Select in the menu Resources > Cloud Platform projects... and enter your project number there
Then google will ask you to setup OAuth
After that, you can move your script to cloud platform and publish.
To publish an addon for G Suite Document editors follow the instructions here
https://developers.google.com/gsuite/add-ons/how-tos/publishing-editor-addons
The specific part about the GCP project is
Technical
The add-on script project must use a standard Cloud Platform (GCP) project. If the script project currently uses a default GCP project, you must switch to a standard GCP project. All collaborators working on the add-on should have access to the standard GCP project.

How to add a Google Apps Script web app as a client in Google API console

I have an app that consists of two parts
an installed application (more specifically: a browser add-on) that runs on the user's machine, and
a web app implemented as a stand-alone Google Apps Script app using HtmlService.
The two parts talk to each other and both access some Google APIs on behalf of the user via Oauth. To do this, I set up an API project in the Google API console. In the section "API Access", I created a client of type "Installed Application" for the browser add-on. For the Apps Script part, Google takes care of the authorization flow automatically.
My problem is that Google does not know that these two clients are part of the same project. Therefore, the user has to go through two authorization steps in a row when executing my app for the first time (first, the Oauth process for the browser add-on and then the automatically generated authorization process from Google Apps Script). This is very confusing to the user, especially, since the splitting between the browser add-on and the web app is rather an implementational detail about which the user shouldn't really have to bother.
Is there a way to unify the two authorization flows? I know that one can add several distinct clients to a single project in the Google API console. It seems to me like this feature is explicitly intended for scenarios similar to mine, where more than one application make up what is perceived as a single service by the user. Unfortunately, web apps that are implemented in Google Apps script don't seem to be compatible with the Google API console because of the way Apps Script generates the authorization flow automatically. Or am I missing an option in the API console or in the Apps Script editor?
For future reference: I found out that Google automatically creates an API project in the Google API console for each Google Apps Script project. This seems to be a fairly recent feature. One difficulty for me was that these API projects don't show up when one goes to the API console, clicks on the name of whatever project is currently opened in the upper left corner and chooses "open". Apparently, the only way to reach the auto-generated API project is as follows:
Go to drive.google.com and open the Google Apps Script project.
Chose "Resources --> Use Google APIs...".
In the popup, click the link to the Google API console.
In principle, this should allow to add additional clients to the project, as long as none of the other clients is also a Google Apps Script project. I haven't been able to test this since it still doesn't solve my specific problem: Sending e-mails from the user's Gmail account seems to be a feature unique to Google Apps Script and I couldn't find an Oauth2 scope for this operation. Therefore, I still cannot ask for all required permissions in a single authorization flow. But if anyone who's reading this has a similar problem with different Oauth2 scopes, the above instructions should fix it for you.
Anyway, I solved my problem in the meantime by no longer using Google Drive to upload files.