How do you get URL parameters in a Google Form using Google Apps Script?
google-apps-script, google-forms, javascript
Solution
I think you can't use your own id, you have to use the id of the Google Form's "Item" object. You can figure out the id by viewing a prefilled form. In the Form edit screen, click "Responses", "Get Pre-filled URL". Fill in the field that you want to use and click Submit. On the new page, you are given a URL in "Share this link to pre-fill the responses" . Examine that url and you can see "get" arguments like `?entry.265525444=mytext` . Replace mytext with whatever you want to be in the field.
The complete URL will be something similar to this:
`https://docs.google.com/forms/d/e/1FA...SkQ/viewform?usp=pp_url&entry.265525444=mytext`
This will display the field on your form, however. I myself was searching for how to make such a field readonly or invisible when I got here, but I hope this shows you a new direction to try.
Problem
So I've got a Google Form where I'd like to pass in a parameter from an email link like this: https://docs.google.com/URL/forms/d/LONGSTRING/viewform?id=12345 I'd like to be able to grab that id and pass it into the spreadsheet recording results. Now I've got writing to a spreadsheet down, but getting the id is problematic. I've already tried: ``` function doGet(e) { var id = e.parameter.id; Logger.log(id); } ``` and ``` function doPost(e) { var id = e.parameter.id; Logger.log("do post " + id); } ``` Both of which throw errors when I view the execution transcript, which I suspect is because they're designed to run within deployed webapps. Additionally, I've tried using plain old javascript to do something like: ``` var formUrl = window.location.href; var formId = formUrl.split('?id=')[1]; ``` which also throws errors when you view the execution transcript . Any other ideas?? Maybe I can get the information in another way?