Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

javascript - How do you get URL parameters in a Google Form using Google Apps Script?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...