How to open Google Forms on Google Sheets - google-apps-script

I'm creating a simple vehicle monitoring system using Google Sheets. I have drawn a shape to be used as a button, and I've assigned a script to it.
Here's the script I'm trying to run:
function newlto() {
var form
=FormApp.openById('1kJLfksSYgOv6Q0UGjdnklg2E5J5R03mIUHoefIvuZ28');
}
The script is supposed to open my Google Form, however, the script runs no problem but it does not open the form, after the "Finished running script" notification at the top-center, nothing happens.

You are trying to open a Google Form from a script. Google Apps Script will not automatically open web pages, and a Google Form is a web page - so you can't write a script to open a form.
You may find it easier to create a simple hyperlink to the Google Form.
The steps to do this (assuming that you have access to the form editor):
Send Form
click "Send",
at the top of the screen where it says "Send via", click the middle icon for the link,
click the link ( or a variation here is to click the "Shorten URL" box to get, well, a shorter URL),
click "Copy" (to put a copy of the link into memory,
switch to your spreadsheet and paste the link into a cell.
This automatically creates a hyperlink.
To access the URL, hover you have to hover the hyperlink, and then click the popup box that appears.
You would probably benefit from reading these topics which cover issues sim
You should read:
google spreadsheet - open external URL from button (created 2018),
Google Apps Script to open a URL (created 2012),
Google App Scripts Function to Open URL (created 2018).

I guess you want to open the form using a button, using something like window.open(); the problem is that Apps Script is server scripting and this method cannot be called from a server script but with a client script. If you try to use it it will prompts an error message indicating that window is not defined.
when you use FormApp.openById(); you are opening the form on the server to work on the Form by using the script, is like doing the same steps manually on the browser but with coding on the server. You can find more information on the Apps Script - Forms website.

Related

Google sheets button to open marketplace with specific addon page?

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?

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?

Google apps script: how to edit/modify an existing script

I have created a Google apps script "to download attachments from GMail" from a tutorial. I executed that script for one time.
Then I logged out of Google. Now when I logged in again, I saw the desired script titled "gmailAttachment2drive" in my Google drive. But I want to edit it again to make some changes to it. But I am unable to do it. I cannot even see the source code of that script.
Here are the different things I tried and the responses I got:
If I click on it, I see some "connect app" pop-up type of page, which just shows a bunch of other scripts developed by other people.
If I right clicked it, I don't see any option to edit the script. I tried all options there but could not edit the script.
When I opened "https://script.google.com/" it doesn't show that script. When I clicked "Open" on the File menu, it showed "No saved projects to open"
So, how do I open an existing script that is there in my Drive?
I searched a lot on Google the following "Google apps script how to edit an existing script" but could not get any help to resolve the issue.
Click the "Create" button. (The button used to create new documents)
Located at the bottom of the menu you will see a "Connect more apps" link, click it.
Add the Google Apps Script editor to your Google Drive
Open the script

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

Embedded Google Drive forms sent blank data

I want to styling embedded Google Drive form. So I create form at Google Drive, run it and copy source code from <form> to </form>. All looks good but when I select form values and click on submit button data sended to Google Drive spreadsheet are blank. If I use iframe that Google recommend all sended data is not blank. What I do wrong?
It sounds like you're viewing the source code from google drive, and copying that into an I-Frame on your own webpage. This won't work since that source code is offline, reserved for sending and receiving data from google only.
I recommend creating your own excel-like spreadsheet in your I-Frame. You may be able to use the same submit button if you configure it to send to your server.