Edit Google form responses through Google sheet - google-apps-script

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

Related

How to disable submit button on google form if the same value already exists in google sheet response?

I working with google forms but im not finding a way to disable submit button on google form if the same value already exists in google sheet response and show message the on the form.

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

Attach a google form to a google spreadsheet

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.

Can I fill in TextItem by Google apps script?

I made a form with Google Form Builder, then I add a script for it.
I can run Session.getEffectiveUser().getEmail() to the respondent's email address. but I cant fill it in the textbox to assist them. Can I do such thing with Google App Script?
I think I found a solution to your problem. But I must admit it was not evident.
In apps scripts documentation you've got everything to create a prefilled url.
BUT for that you need to have a ItemResponse element and I didn't found any explaination to build one. The trick is when you've got an item you can get a ItemResponse from it if you get it as a defined type "asTextItem()".
Best way to understand it, is to watch the code below:
function getPreFilledItem(){
var form = FormApp.openById("YOUR_FORM_ID");
var items = form.getItems();
var itemOfInterest;
for(var i in items){
if(items[i].getTitle()=="YOUR_QUESTION_TITLE"){
itemOfInterest=items[i];
}
}
Logger.log(
form.createResponse().
withItemResponse(itemOfInterest.asTextItem().createResponse("PREFILLED_TEXT")).
toPrefilledUrl()
);
}
Hoping this will help you,
Harold
You can't dynamically modify Google Forms by attaching a script to the Form. See a recent question I asked to get a better understanding.
Basically, you can only use Google Apps Script to create forms in an automated manner. You can't set values for the items as of yet (I certainly hope they add this in the future...).
You can also see the limitations for Forms by looking at the documentation (TextItem, for example).