Refresh G-Connector via Google Scripts [duplicate] - google-apps-script

Is it possible to call a Google Sheets add-on as if it were a function in an Apps Script?
I am trying to automate a few steps like this:
Import/append data from sheet 1 to main sheet 1
Import/append data from sheet 2 to main sheet 2
Merge values/append new values from main sheets 1 and 2 into main sheet 3
All of these steps are done with 2 add-ons. Ideally, I could call those add-on functions with a script and run the script with a button.
Is this possible?

Short answer
It's not possible.
Explanation
Google Apps Script official documentation doesn't include this on the Guides section, by the other hand, there aren't a documented way to call add-on functions other than the custom menus and the add-on dialogs, sidebars, custom functions and triggers, which should be part of the same project directly or of a installed library.

This is possible however all users have to have view permission to the underlining script file that you publish from.
I'm not sure this is bullet proof but to help limit the exposure of the code I've:
1) Share code with option "Anyone at My Domain with the link"
only my domain users can access it (not everyone on the web)
make it a little harder to find (so they can't search for it)
2) Break off any function you don't want users to potentially see into a seperate Library; make this Library private

Related

Updating multiple appscript projects from one appscript

I have scenario where I have more than 60 sheet, and all have appscript project behind them running and managing those sheet.
I want to updat/control those appscript projects all at once, from one different project. So that I don't have to manually go and update them.
I know this solution where we can update it by manually getting OAuth Token from single appscript project but, Is there any way we can just mention sheetID and it updates project behind all those sheet all at once?
From the question
Is there any way we can just mention sheetID and it updates project behind all those sheet all at once?
There is no direct way to do this. Related issue Retrieving Project ID of Container-Bound script (created in 2018, as of the end of 2021 it still has the "New" status).
Assuming that by "SheetID" you mean the spreadsheet id, it's possible to use the Spreadsheet Service and the Drive Service to get a Class Spreadsheet or Class File object, respectively. Unfortunately those classes hasn't any method to retrieve the bounded Google Apps Script project.
The same for the Sheets API, Drive API and the Apps Script API.
The indirect way is to build a list of spreadsheets and their respective bounded scripts but it's clear that this is not what you are looking for. Anyway, build the list of spreadsheet/script projects pairs and store it somewhere (it might be an spreadsheet if the list is not humongous. CLAPS has a command to retrieve the list of the recent projects, and it's possible to get the container id from the script project metadata (see https://developers.google.com/apps-script/api/reference/rest/v1/projects/get)
Considering the above, the advice to make it easier to maintain your scripts "for the next time" is to either use a library or to create and add-on.
Resources
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet
https://developers.google.com/apps-script/reference/drive/file
https://developers.google.com/apps-script/api/reference/rest/v1/projects#Project
Related
How to programmatically create a list of Google Apps Script projects owned by me?
List Google app script projects
Google Apps Script: Get the ID of script bound to a spreadsheet
How to make Google Apps Script library always serve the latest version
If you're asking can you reference different codes from the same document but not the same sheet in a new code, the answer is yes. But, there is no way to manipulate this code other than editing the original code. I would recommend manually getting an OAuth Token from a single Apps Script Rroject.
A different way to control those Spreadsheets can be with a NodeJS project locally, using Clasp and Multi-clasp2 (https://www.npmjs.com/package/multi-clasp2).

Can an apps script macro in a Google sheet be used by other users?

I have a fairly simple requirement for a Google sheets apps macro script - it basically pulls the values from a couple of cells in another sheet and displays them in an alert box.
I've done the macro for this and it works fine. What I now want is for anyone I've shared the sheet with to be able to run the same macro. This is where things have suddenly got a bit more involved! My questions are:
Is this possible? And if so, what's the best way of achieveing it? At the moment, the macro is not available for the test user I've shared the sheet with. I've had a bit of a look around and it seems like publishing the script as a web app may be the way to go - can anyone confirm if that is correct? Or would there be a better option? I don't know anything about web apps so just want to confirm if this is the best option before trying to wrap my head around it all.
If the sheet in question has been shared with a user, but the second sheet which the script pulls data from has not, is it still possible for the user to run the script and retrieve the data? Or would the second sheet need to be shared with that same user as well? (If it would then it kinda defeats the object of what I'm trying to achieve).
Finally, would the user with whom the sheet is shared have to have a Google account in order to do this? I'm assuming so...which is a bit of a pain, but I guess understandable.
Thanks very much
Wokaround
Following the requirements you have described I get that you want your users to trigger an Apps Script function that will alter or get data from your Spreadsheet while only granting your users viewer-only acccess.
As described here only users with editor level access can run functions on your bounded script or activate it when clicking a button in your Spreadsheet.
To overcome this you can create a simple web app with a button that will trigger your function. Users will have to access this web app to trigger the function. The good point is that they will not have editor level access to the Spreadsheet nor to the actual script of the web app (as they will just interact with its user interface).
The web app would be a different script that can interface any of your Spreadsheets editing them or getting any information from them.

What components can be included in Google Sheets Add-on?

I am building a Google Apps Script application for Google Sheets that I would like to deploy as an add-on in the Google GSuite Marketplace. My application has three components:
An embedded custom menu and set of dialog boxes within Google Sheets that allow one set of app users ("User Group 1") to manipulate spreadsheet data
A web app that provides another set of users ("User Group 2") with mobile device access to different set of functionality that involves spreadsheet data
Template sheets (ideally, hidden from the user) that the app can use to generate additional sheets programmatically as needed.
I would like to deploy all components as part of a single add-on. I'd like components 1 and 2 to be bound to the same spreadsheet. In fact, I'd like someone in "User Group 1" to be able to click a button to get the URL for the web app. This would require the ability to peform functions on the "Publish" menu through Apps Script code.
My reading of the documentation on add-ons makes no mention of the ability to deploy an add on that includes (a) a UI embedded within Google Sheets, (b) an associated web app that operates on the same user spreadsheet, and (c) template (hidden) sheets. Does anyone have any experience with this, or suggestions on how to proceed?
At present, the only solution I see is to deploy two separate apps (components 1 and 2), but then the web app would not be bound to a specific spreadsheet and hence would need to use a different API. As for accessing template sheets, I think it's possible to access an external sheet through a URL, but I do not think it's possible for an add-on to include template sheets.
Number 1
Add-on User interface
Add-ons can create menu items and open dialogs or sidebars. For custom interfaces, the HTML service offers client-side HTML, CSS, and JS with a few limitations: notably, our security sandbox doesn't work with many JS libraries.
Custom sidebars
A sidebar can display an HTML service user interface inside a Google Docs, Forms, or Sheets editor.
Number 2
I am not completely sure that I understand your deployment question - however
Both standalone scripts and scripts bound to G Suite applications can be turned into web apps, so long as they meet the requirements below.
I was able to deploy both an add-on and a web app from a single Standalone script
Number 3
Use the copyTo(Spreadsheet) to copy a sheet from a different spreadsheet to the one you are working on and change the name with setName().
Or you can make a template sheet in the same spreadsheet and use hideSheet()

How to share a Google Spreadsheet that utilizes Google App Scripts within a company domain?

I have a seemingly simple problem that seems to get more complicated the more I get into it.
I have one spreadsheet document.
This spreadsheet utilizes a google apps script, that in turn utilizes various APIs: Domains, Sites, Spreadsheets...
To use this spreadsheet I have to take a few steps -
Authorize the spreadsheets. This dialog only comes up if I use the
script editor, otherwise the Spreadsheet fails silently.
Enable Domain API in Editor -> Resources -> Advanced Google Services
Enable Domain API in Google Developer Console to a seemingly hidden
project that is attached to my spreadsheet. The only way I can access this secret page is through the Advanced Google Services menu in step #2.
After getting through these hurdles, the spreadsheet now functions correctly without having to use the Script Editor.
Now I want to share this spreadsheet with other users in my company's domain.
Is there any easy way to do this, or will every single user I share it to have to jump through these hurdles as well?
Am I thinking about this wrong? The documentation states the script is 'attached' to the spreadsheet. But the more I get into it, the more separate these two things seem to be. I can share a spreadsheet - but the script won't function properly. I can publish a 'web app' with the script editor - but it won't come with the spreadsheet.
Any help appreciated
Frusteratingly yours...
Other users will have to have the same domain permissions as you do.
An approach you could take is have all the permissions related work done on a script that is published as a web app that will take url parameters (to trigger tasks), which is run as you and accessible to others.
From there, your original script can call the published url and send instructions via parameters.
https://developers.google.com/apps-script/guides/content

How to make set of scripts available for all my Google Spreadsheets?

Excel supports the concept of a PERSONAL.XLS file which contains my personal scripts, which I want to be able to use on any spreadsheet/workbook that I open.
How do I do similar in Google Docs, i.e. have a set of scripts which, regardless of which Google Spreadsheet I open, will cause the onOpen event to be run and will thus add my extra menu?
You cannot do that in Google Spreadsheets. However the best practice is to
Write a standalone script with your onOpen and other functions.
Publish this as a library
Write a shell onOpen in each of the spreadsheets that you create
manually. :( This shell function will call the library's onOpen.
However, if you create a copy of a spreadsheet that has an associated script, then the copy will also have the script in it.
1) You can open your Script and from the Publish menu select "Test as add-on".
2) Now under "Configure New Test" you can select a document and then run the add-on for that doc.
Unfortunately you have to do this for each document one at a time. I would really love it if there was a way to tell a script to be available for all my spreadsheets, or at least have an easy way to install a personal add-on on a per-sheet basis just like you can install an add-on from the marketplace, kinda like a personal marketplace.
Although not recommended, You can also copy set of scripts to all other google spreadsheets programmatically using AppsScriptApi