Attach a google form to a google spreadsheet - google-apps-script

I'd like to create a form by google script.
This is pretty easy but I'd like to attached this form to a spreadsheet (no only the response), like I would have created it by the UI.
Is that possible ? Given the Formclass or FormApp is doesn't seem so. Is there a way around ?
EDIT: My goal was to create the form with the script and having the same result as if the user had had the form created from the UI interface (the main difference being having the form menu in the SS UI). It's apparently not possible.

You're right - it's pretty easy once you have the trick. Use FormApp to get the published URL of the form, UrlFetch to grab its html, then the HtmlService to present the form in the spreadsheet's UI.
See Single Google Form for multiple Sheets.

Related

Edit Google form responses through Google sheet

I know it's not possible to directly edit the Google form response by editing the Google sheet, but I was hoping to have a work around by using this https://xfanatical.com/blog/how-to-edit-google-forms-responses-in-the-spreadsheet/#source-code.
The script generates a link through which the response can be edited, but I was hoping that when I change a response in the sheet, it would be updated in the link as well and I would only have to hit the resend button.
Does anyone know an easy solution where I can update responses in the sheet and they also will be visible in the form?
Thanks!
You could create a link with the responses already on the form, as you mentioned, but also using Apps Script you can get the responses from the Sheet and pre-fill the form with those responses.
The workflow would be:
Edit the answers on the Sheet
Get those answers on Apps Script
Pre-fill the form with the new answers
Create the link to the form with the new answers
Reference links:
createResponse()
Class FormResponse
toPrefilledUrl()
Also you can check this previously solved question from Stack Overflow:
Prefill a Google Form using data inside Google Spreadsheet

is there a way to make a google form response be formatted and sorted on a sheet with multiple pages

I have a google form that sends responses to a google sheet, I want to be able to populate different pages in the sheet depending on a selection from a drop-down menu in the form.
I would also like to format it differently than how the form automatically populates the sheet if this is possible
I have looked for some proper documentation on how to do this but it's hard to find for me, I have tried a sheets formula but this did not work and using google apps script is hard for me since I have no understanding of how it works properly.
=FILTER('Form Responses '!A2:Z,'Form Responses '!B2:B="topic")
=QUERY('Form Responses '!A2:Z,"where B='topic'")
this gives me the no matches are found in filter evaluation error
=query('Form Responses'!A2:H,"Select * Where B='topic'")
Adding this to the seperate pages fixed my problem with the filtering and using templates lets me keep the formatting i wanted, thanks cooper!

Displaying a Google form on sheets

I am creating a form for users to input information on a Google spreadsheet. They will access the spreadsheet and then click on an image that is linked to a script. When the image is clicked, I want a form to appear. Then I want the input from the form to be accessible in the script.
I am able to create a form but the form does not appear on the sheet. Here is the code thus far for the GS script
function startForm() {
var form = FormApp.create('myForm');
var item = form.addCheckboxItem();
item.setTitle('What would you like to do?');
item.setChoices([
item.createChoice('Budget Inquiry'),
item.createChoice('Add Purchase')
]);
var choices = item.getChoices();
// then I can respond to the user's choice
}
I would like this simple form to just appear on the google sheet. Any input would be appreciated.
Instead of creating you own form with script, just go to the insert menu of your spreadsheet and select form. Enter you question and your two choices. Close the form. You will see a form response sheet created in your spreadsheet. Also, a menu item Form will appear on your menu. Then go to the script editor and from the menu select Resources. Select Current Project Triggers and set a new trigger for onFormSubmit. You can then enter a function onFormSubmit to do whatever you want done when the form is submitted getting data from the form response sheet. There is plenty of documentation you can Google.
The way in Google Sheets to display external content other than images and Google Drawings is by creating a dialog or sidebar with the related content embeded.
There is a similar question that includes an answer that shows how to do this:
Single Google Form for multiple Sheets

Autocomplete Google Form based on values in spreadsheet

I'm writing a script to autocomplete some fields in a Google Form based on a field that has started to be filled out. For argument's sake, let's say it's address. So when a user fills the form out like so:
And if in a spreadsheet called defaults there is a row with this address:
Not only that field is updated, but any other fields that match are, too (like name and email).
Does anyone have any suggestions for me? My research has turned up nothing too useful for this case.
It's not possible to create an autocomplete field in a live Google Form. You can create a stand alone Apps Script Web App using HTML, CSS, and JavaScript. You could even style it to make it look like a Google Form.

Google Apps Script UIApp : no way to create a clickable row in a dashboard tableChart?

I am a beginner in programming and I made a dashboard (populated by a spreadsheet) with Google Apps Script UIApp for my Google Apps website but I can't find the way to create a clickable row in the tableChart (I would like to open a link to a shared document previously stored in the Drive by clicking on each row). It seems impossible to use the Google Visualization APi in this UiApp. I tried to create a Handler but i was not able to link it with the tableChart...Am I wrong ?
Charts are used to display data, not to create interactive UI elements. You may want to look into using UiApp's FlexTable class to accomplish your goal.