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

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()

Related

Refresh G-Connector via Google Scripts [duplicate]

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

How to share a google web app outside a domain preferably without creating a marketplace addon

I'm new to apps scripting and have created a web app which is container bound to a spreadsheet.
The app provides an html form for patients to record blood pressure readings as they take them during the day. A query string on the web app url identifies the individual patient and puts their readings on a sheet, unique to them, as they submit them. The script is deployed as a web app (Publish -> Deploy as web app) and in my development account it works well.
Now I want to share the script with a few other accounts not in my domain, so that they can use it independently with their own patients, with their own web app url, with readings going onto their own spreadsheet and for me to be able to maintain the code centrally.
Researching this I see official addons are now provided through the Gsuite Marketplace. It appears my choices for 'sharing' are these:
create an officially reviewed addon and put it in the Gsuite marketplace but creating an addon for the world is not what I want to do (atm anyway!)
create a private addon for inside one domain but I want to share it with several domains
there appears to be a system for testing the script as an add-on, without publishing it and for sharing the testing but this is mentioned in the Gsuite addon docs but not mentioned in the Editor addon docs and anyway it's for testing.
share the spreadsheet in my account but then all readings end up on my spreadsheet
share the spreadsheet and code to other accounts so they can make a copy but then I can't maintain the code centrally
Can anyone suggest the best way to share this web app script so other accounts not inside my domain can use it independently but ideally so I can maintain the code centrally? Thank you.
I see two solutions here. One is to add a small amount of "user management" code to your tool. For example, include some query parameters on your base url such as email and authorization key. Set up a user-management spreadsheet with your list of users, mapping their email to a secret randomly generated authorization key, and their data spreadsheet ID.
When the script is accessed with a valid email/authorization_key combination, it then opens the relevant sheet and does its thing.
In this scenario, you would either need to have access to all the relevant spreadsheets (if the code is executing "as you"), or you would need to figure out a standardised file layout or approach that let your script locate the right files on each users drive (if the code is executing "as the user accessing the web app").
Another solution here is to use an Apps Script Library. Using a library would allow you to keep the bulk of the code in the library, while having lightweight "wrapper" code bound to each of the other users spreadsheets. This wrapper code would simply pass doGet/doPost, and any other function requests back to your library.
For example:
function doGet(e){
return YourLibrary.doGet(e);
}
function doPost(e){
return YourLibrary.doPost(e);
}
function aCallback(a,b,c){
return YourLibrary.aCallback(a,b,c);
}
In the library scenario, each sheet and script can be private to the individual users, you would just need to walk them through the initial setup/deployment, and occasionally have them bump the library version and re-publish the web-app in their copies.

One question survey app Google Apps Script and Google Sheets with user management

I have to do a little bit of "crowdsourcing" for my work and it would consist in a very simple web app where a user can register/log in, and then be taken to a page where a picture is shown to a user and submit a number.
I'd like to be able to set up a few rules to choose which picture the user will see (so he won't have to answer twice the same question and also to allow some overlap between users to compare their answers).
We can assume that I have a google sheet with a list of images URLs that can be accessed and that I would like the answers to be populated there.
I figured that this tutorial would be a good start since it handles user creation and management and user can submit ideas :
Creating a CRUD Web App with Google Sheets
That being said I'm a bit clueless, I've tried to look for sample scripts deployed as web app but it's hard to know where to start.
I'll appreciate any help !
Google Apps Script is, basically, a javascript environment with a set of libraries that interact with the Google Apps. For instance, to read or store information from/to Google Sheets or Google Docs. If you know javascript, you can create simple applications there. In addition, you can create plugins for Google Applications if you are interested.
A very simple example
Suppose you wanna display an HTML page. You can create an stand-alone script (an script not-bound to a G suite application) and use the content or the HTML services.
You can create a function that sends a simple message to the browser using the ContentService:
function doGet() {
return ContentService.createTextOutput('Hello, world!');
}
Or you can create a function that sends an HTML file in the same project using the HtmlService:
function doGet() {
return HtmlService.createHtmlOutputFromFile('Index');
}
Once you have created the function, you must deploy the script as a web application.
Save the script as a new version doing File > Manage Versions and Save new version.
Then, publish the app using Publish > Deploy as web app and provinding information about the permissions for the application.
After Google publishes the application, it gives you an URL to access the application,
You may check more in a simple tutorial on producing content with Google Apps Script. In addition, you may check the google guide to use the HtmlService to provide templated content, i.e. where the HTML are templates which data is provided by javascript functions and variables.
Getting started with Google Apps Script
To start, you may check some tutorials in the internet:
Google has some tutorials and a series of Youtube videos.
In addition, you may find multiple resources for Google App Scripts that may help you:
Google has a list of sample projects
Tanakeich has a list of resources for taking advantage of Google Apps Script.
Oshliaer has another list of resources.
There are Google Codelab (tutorials) for Apps Scripts. They include a lab for using Google Sheets as a reporting tool and for creating a Hangouts Chat bot with Apps Script
Developing Google Apps Script projects locally
Although Google Apps Script provides a web interface to create your applications (your scripts), a better idea may be to create the software locally, using more-traditional tools for Javascript.
Clasp is a command-line tool to develop locally Google Apps Script projects.
Google has a codelab that teach you how to use clasp.

Count forks, similar to Github, for a Google sheet in which I am building an app

Update: Question regarding a proper distribution mechanism in the first place: Publish and distribute a Google Sheets with App Scripts so user gets private copy of sheet
I'm developing an app inside a Google Sheet for which the delivery is basically just hard copy / forking. Does Google Docs have a forking mechanism that counts or tracks forks in any way?
Alternately is there a way to hack this? I could give the user an optional link to register (i.e. Google form) their sheet.
There's no real forking of app script projects, but for the delivery system you describe, google app add-ons do the trick
See the doc here
You can deploy and app for all users of the g Suite domain or through a google group or finally to a specific list of users defined by you

Google Apps Script - How To Publish / Install A Container-Bound Script

I have a document container-bound script, that I would like to publish, I would like to make it available to people in my google apps organization. I know the script gallery is only available to spreadsheet apps, so how do I publish it. Or, more specifically, currently the script is bound to one document, how do I make it run on all documents? My user base is fairly small, about 300 people, and I can have each one of them install it if need be.
Thanks,
Ari
There are limited options for distributing container bound scripts. When a document with a container bound script is copied, the script is also copied. So if the 300 people in your organisation copied the document they would also have a copy of that script. The issues with this techniques is that the script is only attached to that particular document and creating a new document, rather than taking another copy of the template, or opening an existing document will not include your script functionality. The other issue the script in the copies of your template becomes orphaned and you cannot push updated versions. Using Managed Libraries addresses this to a degree but the end user still needs to select the newer version of the script in the script editor.
A way to mass deploy your script in your organisation is using Google Apps Script authored Add-ons. Add-ons are installed by users and become available to every document they work on. The script behind add-ons can also easily be upgraded without any user intervention. One issue with this approach is all add-on's need to be approved by Google. This introduces a risk that Google will not publish your script as an add-on. Whilst there is a public store of add-ons after your project is approved by Google there are visibility options to restrict access and prevent there general visibility. As per add-on publication step #12:
In the "Visibility options" section, select which users will be able
to find your add-on — usually either all users or only users with an
account in your Google Apps domain.
Hopefully when add-ons leave developer preview Google Apps domains will have more control over publication and visibility (I've opened a feature request for this)