Google spreadsheet reading parameters from its own URL - google-apps-script

I would like to open a Google Spreadsheet with a few parameters.
Can I add these few parameters in the URL to open the spreadsheet, and then in the spreadsheet load these into some cells?
The spreadsheets in question are privately shared, and the users using the URLs is granted permission to edit.

Sandy Good provided an interesting answer and that workflow is indeed the only possible one but there is a major issue in that a webapp deployed this way won't be able to "open" your spreadsheet in the common sense of "open", ie open in a browser window to work on it normally.
At least not without a user action like a click on a link that would open the sheet in a new tab. Finally you would have a 2 steps process:
Launch the webapp via an URL with parameters that would write some values in the spreadsheet without seeing it and
Open the spreadsheet using a link shown in step 1... retrieving the values that step 1 wrote in some cell
Very cumbersome and nothing would prevent users to go directly to the spreadsheet without using your special URL...
All in all , it would be useless.
So I'm afraid the real answer it simply "no, not possible"

Here is a table of triggers that are available to the different Google Products:
Available Types of Triggers
In a Stand Alone app, you can run a doGet() function. The doGet() function runs automatically. There is an e.parameter option available to doGet(e) that will parse URL search string settings. But a doGet() function can't be added to a Sheet.
The URL parameters that are available are listed in this documentation:
URL Parameters
But, those URL Parameters are for Web Apps and Google Sites Gadgets, not for a Google Sheet.
You could have an intermediary Google Apps Script that you send the URL Request to, and then the Apps Script processes the URL Search String parameters, and then opens up the spreadsheet.
So, instead of using the Google Sheet URL to open the spreadsheet, you'd be using a URL of the deployed web app. Then the user would need to click a link to open the spreadsheet.
Once the web app parsed the URL Search string values, you would need to write some kind of script that did something like write those values into your spreadsheet using the Spreadsheet Service

Related

On a Google Sheets, is there a way to trigger a Google Script function from a standalone webpage <button>?

I've created a small electron app that shows data from a google sheet via sheetrock.js to display table data. I've added a form that submits data to the google sheet with the help of triblondon's git
Now I'm trying to Implement a simple button on the electron app that will move populated rows from one sheet to another, creating a history. But for the life of me, I can't find a method of doing so that doesn't involve sending json data like the method above, writing to a cell and just doing formulas from there.
I'm just looking for a simpler, more direct approach by just invoking a function on the google script side (button + javascript probably).
Thanks for any help you can provide.
You can deploy your script as apps script. You will have use the public URL to be triggered by your button.
You can check everything about it on the Web Apps documentation.

Enable Google Sheet Protection via Google Script

I have been searching for a solution to a Sheet Protection issue, I have a Sheet that includes automated scripts to write data into the Sheet below from some fields at the top. I want the user to be able to provide the data in the fields at the top and then to run a script that adds the data below. The script to add the data works fine for the owner of the sheet if Protection is enabled, but fails for any user that has Edit rights as the Protection cannot be cleared by script for the data to be written to the bottom of the sheet.
https://developers.googleblog.com/2015/02/control-protected-ranges-and-sheets-in.html
I found this code from a Google blog post a few years ago and have tried variations without success....is this type of approach just not possible with Google Sheets and Google Script ?
Unfortunately, that is not currently possible to run a bound script as the owner without using a workaround. Scripts can only be run as the owner when they use Triggers or when you make a standalone Script Web App. You can see this for more information.
This should bypass fooling around with scripting protection ranges!
The Workaround!
There is a way you can get around this by creating a web app so that your bound script talks to the web app which runs on the spreadsheet. See this answer for more information.
So the process looks like this: User clicks a button that runs a function on a bound script. This function makes a web call to a web app that can run a function as the person who created the script.
I would also recommend you pay attention to a comment by Augustine C:
...you may also find it helpful to have a shared secret key saved in your spreadsheet and then verify it using the backend webapp script, or to perhaps verify that the recipient of the email is, in fact, also an editor of your Google Sheet.

How to avoid re-authorization request for a copied Google Spreadsheet + script

I have a spreadsheet that functions as a template for weekly reports. At this point I copy the undated template sheet using DriveApp to a file that has a date in its name. The user is shown the date-specific spreadsheet and can interact with it. When done the user instigates a function that copies of portion of the spreadsheet data to a third file.
Every time the user calls the function an authorization request is shown. I am trying to avoid that authorization request. Is this possible?
I am using a stand-alone Google Apps Script to copy the original template to the date-specific file. I have considered trying to perform all of the UI there. However there are too many contingencies to make that practical. As it stands now once the template is copied then the stand-alone script returns the URL of the date-specific file and ends.
Every time the user calls the function an authorization request is shown. I am trying to avoid that authorization request. Is this possible?
Publishing your script as an add-on would facilitate this; each user would need to authorize the add-on once, and that authorization would remain in effect in any sheet the add-on was used in.

google spreadsheet script html service for all

I wrote a google spreadsheet script incl. html service. Now I like to publish the html service as a survey. Everbody shall see it without registration at google but it should be not allowed to see the results of all participants.
Have you an idea how can I reach this?
I tryed a lot of publish options but I didn't reach my goal. Do you?
Right now, your Apps Script Project is probably bound to the spreadsheet. If the users who are submitting the form, never need to see the spreadsheet, then create an Apps Script file that is not bound to anything, it's "Stand Alone". Then do NOT share the spreadsheet. If you share the spreadsheet, then people who the file is shared with can VIEW the spreadsheet. It is possible to hide and protect sheets and ranges. And of course you can make settings for some users to be able to VIEW the spreadsheet, and others to EDIT.
If you share the spreadsheet file, then everyone it's shared with has VIEW permissions. You can't share a spreadsheet file and not give VIEW permissions. But, if you want some users to be able to see just some sheets in the spreadsheet, and not all the sheets, then you would need to write some code that ran when the Spreadsheet opened, and that code would be hiding and unhiding sheets depending on who opened the spreadsheet. Only users with EDIT permission can unhide a hidden sheet. So, that's an option. You can hide a sheet from anyone. But a user with EDIT permission can unhide the sheet. If you want to hide a sheet from someone with only VIEW permission, (They can't unhide it) then have code run onOpen() that checks the user, checks their permissions and either hides or unhides the sheet.
If the people submitting the form, never need to view the spreadsheet file, then don't even share the spreadsheet URL with those users. Just use the Stand Alone HTML Service as your "front end", "User Interface" with the users who never need to view the spreadsheet.
So, if the people who are using the HTML don't need to ever view the spreadsheet, then don't give those people the URL to the spreadsheet. Give them the URL to the published app. In that scenario, the users of the published app will never see the spreadsheet. The published app is essentially a website, with no real domain name.
The solution for you, depends on how simple or complicated the sharing, editing and viewing settings need to be.
When opening the script file, you need to use the Publish >> Deploy as web app option.
Then, choose the version you want to deploy as webapp or create a new one, set the app to execute as you, and add access to anyone (even anonymous). Like this:
The important thing is that the function that's called when someone access the URL that's shown for your web app, is a function called doGet(). So you must rename the function you use to display the UI and Form to doGet(). This function should return a valid HTML Output (normally using the HTMLService or the deprecated UiApp service).
So this:
Gets you this:

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