问题
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?
回答1:
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.
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.
回答2:
I am assuming you are trying to get the form id?
You will need to set up a trigger that will run on form submit.
function onSubmit(){
var form = FormApp.getActiveForm();
var formID = form.getId();
}
来源:https://stackoverflow.com/questions/21554204/how-do-you-get-url-parameters-in-a-google-form-using-google-apps-script