Google sheets button to open marketplace with specific addon page? - google-apps-script

Is there a way to write an apps script function that opens up google workspace marketplace with a specific addon page? I've seen some addons do this.
Like I want to create a button drawing on my sheet and assign an apps script function to it that opens up the marketplace on that sheet with a single click.

The "trick" is done by creating a spreadsheet from a template having an add-on.
When a user that have not installed yet the add-on tries to run the add-on, the Marketplace listing will be shown, otherwise the function assigned to the button will be ran.
Broad steps
Preparation
Create the add-on
Create the spreadsheet to be used as a template
Install / activate the add-on on the spreadsheet
Add the button and assign on of the the add-on functions.
Submit the spreadsheet to the template gallery
Distribution
Use the template to create a new spreadsheet
Share the new spreadsheet to the user(s)
Use
The user open the new spreadsheet
The user clicks the button
Resources
Create a file from a template

You can't open a Dialog like the mentioned
Google Spreadsheet cannot contain a button that opens an iframe since it's outside docs.google.com
As a workaround you can open the add-on link in another tab rather than in a dialog on the same Spreadsheet page. There are several posts related despite they are not the same in your case but pretty much what you are looking for:
Google Apps Script to open a URL
How do I open a web browser using google apps script?

Related

How can I prompt a user to save the newly auto-created google doc to a google drive location of their choice

I've created a google apps-script script to create a google document report based on the filtered options in a google sheet. The report generation is started from the google sheet.
I can create the required google document report but would now like to prompt the user to save it to a specific google drive location of their choice using the google drive Move To menu option. When the report is generated, I'd like a prompt to appear stating "Save Report to.." and the user is then displayed the google drive prompt as per this example
and can then select where they want to save it on google drive. Any and all help appreciated.
If the google drive menu options are not integrated, is there another way to prompt the user so they can select which location to store the doc?
Very few built-in user interface menu options are integrated with Google Apps Script, actually most built-in user interface dialogs can't be open by using Google Apps Script but you might use the Google Apps Script HTML service to build your own dialogs.
To help you create your own dialog to handle files in Google Drive you might use Google Picker.
Resources
https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs

Are Google scripts attached to a readonly spreadsheet visible to the user?

I'm working in a Google Script that runs on a a Google Spreadsheet and creates an onEdit() trigger on it.
I would like to know if this script is somehow visible (through Google's interface or any kind of source code inspection) to the users that access the table with readonly permissions.
From my understanding users would not be able to access such a script, since they are suppose to run on Google's server side and not on the client browser. I couldn't find anything about that on App Scripts documentation.
Regarding the use of a web browser developers tools (like right click and selecting Inspect) over a spreadsheet they will not the script code if you do right clic over an spreadsheet but it might show the name of functions called by a custom menu or image with an assigned function, not the code of the onEdit function.
User with view access can't view the code but, if you didn't disable disabled make a copy, they see the code if they made a copy of the spreadsheet.
An alternative to limit users to make a copy of the spreadsheet is to publish your script as an add-on.
Related
How to protect the Apps Script code in a Google spreadsheet?

Standalone Script for Google Sheets

I am looking to locally use a Google Apps Script with one of my Google Sheets (Attached to a form) that will be accessible to all emails that have permission to access the sheet, but I don't plan on publishing this script to the public. Do I still need to publish in order to use this script, or will I be fine just adding an onSubmit function for my Google Form as a trigger for my script to run in my Google Sheet? And can I use installable triggers if I plan on operating this script as a standalone only attached to this one Google Sheet?
Do I still need to publish in order to use this script
No: If you own the spreadsheet (or have editor permissions on it), your script can remain private. A script does not need to be bound to a Spreadsheet except if it will use:
Spreadsheet UI (getUi(), custom menus, dialogs and sidebars)
"Active" items (getActiveSpreadsheet(), getActiveSheet(), getActiveRange(), getActiveCell())
...will I be fine just adding an onSubmit function for my Google form as a trigger for my script to run in my Google Sheet?
Yes: Your standalone script can have installable triggers associated with Google Apps items such as spreadsheets, documents and forms.
And can I use installable triggers if I plan on operating this script as a standalone only attached to this one Google Sheet?
Yes: There's nothing special about the 1:1 relationship; the same trigger could be installed for multiple spreadsheets.

onOpen trigger for view-only users

The built-in onOpen trigger in Google Apps Script only runs when a user with permission to edit opens a spreadsheet or document. I am developing a spreadsheet where only developers have edit privileges and all other users must have view-only privileges.
How do I create an onOpen trigger that fires when view-only users open my spreadsheet as well as those with edit privileges?
You can't, because it's not supported. Google Apps Script, embedded in either Google Sheets, Docs, Forms, and as an add-on, runs only for editors.
The alternative is to Publish as a webapp, so the viewers open that instead of the sheet directly, or open the webapp (on another tab, not inside the sheet) from a link in a sheet cell.
From the "Restrictions" section of trigger documentation on triggers - both simple and installable:
They do not run if a file is opened in read-only (view or comment) mode.**

How do I access my app scripts?

I work for a university which uses Google App for EDU. Recently, I decided to begin testing app script to see how it could be of use to our organization. I have been able to create new app scripts and run them without issue. However, I have found that once I close the browser editor tab, I am not able to retrieve any script I've wrote unless I have the editor url saved (ie. I dont see any of my script in my google drive). Is there a particular app script site where my scripts are listed?
Thanks,
Bryan
The long method i use to get to see all my App Scripts is:
open an existing spreadsheet, or simply create a new spreadsheet
go to Extensions > Apps Script
click on the "Apps Script" logo in the top left corner
This will take you to: https://script.google.com/home
The short method is just to have that link (above) saved on browser toolbar and click it whenever i need to.
to be able to starts new script from the drive you have to connect script app to your drive using the Browser interface like below :
from the connect more apps at the bottom search for "script" and add it.
If you created scripts from inside a spreadsheet, they are tied to that sheet and will not show up in Drive; you can find them via the "Script Manager" menu in that spreadsheet.
All standalone scripts will be visible in your Google Drive. Did you write your script inside a spreadsheet or a Google Site ? If so, you have to open the spreadsheet or site to see your script.
If you indeed have a standalone script, make sure you click the 'All Items' on the left hand side of Google Drive or use search.
If you've created a new script from script.google.com and have saved it, it'll appear in Drive under the root My Drive folder.
If you created one from inside of Drive by clicking the red Create button then Script, it'll be in the folder which you last clicked on before clicking Create. If you don't remember what folder you created the script file under, click the Recent folder name to find it.
If you've started one inside a Form , Sheet, or Doc you'll have to remember where the Form, Sheet or Doc was located in Drive.
You can search all your scripts in Google Drive using app:"Google Apps Script" or by selecting Google Apps Script under Opens With from the drop down menu.
As pointed out by #Mandy, this assumes you have added Apps Script as a connect app. See answer from #Serge on how to do that.
Try the handy dashboard/central location for scripts:
https://script.google.com