如何使用Google Apps脚本获取Google表单中的网址参数? [英] How do you get URL parameters in a Google Form using Google Apps Script?
问题描述
所以我有一个Google表单,我想从这个电子邮件链接中传入一个参数: https://docs.google.com/URL/forms/d/LONGSTRING/viewform? id = 12345
我希望能够获取该ID并将其传递到电子表格记录结果中。现在我已经写下了一个电子表格,但是找到id是有问题的。
我已经试过了:
函数doGet(e){
var id = e.parameter.id;
Logger.log(id);
}
和
函数doPost(e){
var id = e.parameter.id;
Logger.log(do post+ id);
}
当我查看执行记录时,因为它们被设计为在已部署的webapps中运行。
另外,我尝试使用普通的旧javascript来做类似的事情:
var formUrl = window.location.href;
var formId = formUrl.split('?id =')[1];
当您查看执行记录时也会引发错误。
任何其他想法?也许我可以用另一种方式获取信息?解析方案
我认为你不能使用你自己的id,你必须使用Google表单的Item对象的ID。您可以通过查看预填表单来确定该ID。在表单编辑屏幕中,点击回复,获取预先填写的网址。填写您要使用的字段,然后点击提交。在新页面上,您会在分享此链接以预先填写回复中获得一个网址。检查该网址,您可以看到获取参数,如?entry.265525444 = mytext。将mytext替换为您希望在该字段中的任何内容。
但是,这会在您的表单中显示该字段。我自己一直在寻找如何在我到达这里时使得这样的领域只读或不可见,但我希望这会给你一个新的尝试方向。
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?
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.
这篇关于如何使用Google Apps脚本获取Google表单中的网址参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!