I am building a Google Form that I am the only one to use. I use the form 2 times a day (more or less) and I would like some of the fields to be prefilled with the value of the last response I gave, because their values are not suppose to change often.
I save my responses in a google spreadsheet so I could get them from there but I am very new to Google Apps Scripts and I haven't seen an event that triggers when someone opens a form to answer it yet. I'm not even sure such an event exists...
And also, I would like to access my form from always the same URL (so no prefill that way) because I saved the URL as a favorite on my smart-phone's desk and don't want to change it every day :)
So, is there a way to prefill a Google Form using data from the last response or at least an event that triggers when answering the Form ?
Thanks in advance
There is both an On Form Submit and On Open trigger. In the Apps Script code editor, click on the Resources menu. Create an Apps Script that is tied to the form. There is a Tools menu in the Form Editor. Use the Tools menu to open the Apps Script code editor.
So, retrieving the last value from the spreadsheet is doable. I can't find anything that makes me think you can pre-fill a form field. But I hope I'm wrong, and somebody has the answer.
You could have a script that simply writes the last value to the new row if a certain response field is empty. So instead of pre-filling the field, just leave it empty if you want the same value written. Although, if you don't know what that value is, you might not know if that's what you want entered again.
There is a way to deal with that though. You could write the last value in the spreadsheet into the help text of the form item.
Google Documentation - Form Set Help Text
So, you could know what the last value was by looking at the help text.
Or I'm wondering if you could set the choices in a List Item:
Google Documentation - Set Choices
If you want to do more work, and learn HTML, you can do what you want with an HTML app.
来源:https://stackoverflow.com/questions/26147287/prefill-a-google-form-using-data-from-the-last-response