如何为Google表单生成预填表单网址 [英] How to generate a pre-filled form URL for Google Form
问题描述
在最近的一次更新中,Google推出了一款新的Forms产品Google文件。如果您打开电子表格中的工具菜单,则会看到一些新选项。
在新的表单响应菜单中,一个选项是获取预填充URL。这会打开一个对话框,其中包含您可填写的表单版本,以及您何时提交
它,您会收到一个URL,可用于打开一个Live Form您预先填好的数据准备就绪并等待您。该网址看起来像这样...
https://docs.google.com/forms/d/--Form -ID - / viewform?entry.1094330118 = Something& entry.1471717973=stack@example.com& entry.540962741&entry.787941281& entry.1873343651
表单中的问题具有固定的标识,例如 entry.1094330118
。它们可能预先填充了一个值( entry.1094330118 =某物
)或空白( entry.7879412
)。
在apps-script中,我想为我的表单的用户生成这些预填充的URL,因此我可以为它们提供更新。我的用户不是应用程序域的成员,所以我没有嵌入编辑您的响应链接的选项。
如果我可以获取关于表单的信息,我将可以拼凑URL。虽然我可以通过UI来创建一个URL,并解析它以获取该表单的信息,但我想要一个可以使用任意表单的解决方案。
- 如何以编程方式确定问题ID?
- 使用新的
Forms产品,是否可以通过任何应用程序脚本
API获取表单? (我知道getFormURL()
- 这不是我的意思。) - 有了问题ID,我可以获得更多信息关于这个问题? (问题文本,类型等)
并编辑他们的回复,请看看这里: http://productforums.google.com / forum /#!topic / docs / LSKKCR3VHC8
复制/粘贴以下代码:
function assignEditUrls(){
var form = FormApp.openById('1MonO-uooYhARHsr0xxxxxxxxxxxxxxxxxxxxx');
//在此处输入表单ID
var sheet = SpreadsheetApp.getActiveSpreadsheet()。getSheetByName('Form Responses');
//根据需要更改工作表名称
var data = sheet.getDataRange()。getValues();
var urlCol = 4; //填充URL的列号; A = 1,B = 2等
var responses = form.getResponses();
var timestamps = [],urls = [],resultUrls = []; (var i = 0; i< responses.length; i ++){
timestamps.push(responses [i] .getTimestamp()。setMilliseconds(0));
urls.push(responses [i] .getEditResponseUrl()); (数据[j] [0]?url [时间戳.indexOf(数据[J] [0] .setMilliseconds(0))]: '']);
}
sheet.getRange(2,urlCol,resultUrls.length).setValues(resultUrls);
}
I'm looking for a programmatic way to automate the generation of pre-filled URLs for google forms.
In a recent update, Google introduced a new Forms product to Google Docs. If you open the tools menu in a spreadsheet, you'll see some new options.
In the new Form Responses menu, one option is "Get pre-filled URL". This opens up a dialog containing a version of your form that you can fill out, and when you submit
it, you receive a URL that can be used to open a Live Form with the data you pre-filled ready and waiting for you. The URL looks something like this...
https://docs.google.com/forms/d/--Form-ID--/viewform?entry.1094330118=Something&entry.1471717973=stack@example.com&entry.540962741&entry.787941281&entry.1873343651
The questions from the form have a fixed identity, e.g. entry.1094330118
. They may be pre-filled with a value (entry.1094330118=Something
) or blank (entry.7879412
).
In apps-script, I'd like to generate these pre-filled URLs for users of my form, so I can provide them for updates. My users are not members of an Apps Domain, so I don't have the option of embedding an Edit your response link.
If I can get the information about the form, I will be able to piece together the URL. While I can go through the UI to create one URL, and dissect it to get the info for that form, I want a solution that will work with arbitrary forms.
- How can I programmatically determine the question IDs?
- With the new
Forms product, is the form available to me through any apps-script
APIs? (I know about
getFormURL()
- that's not what I mean.) - Armed with a question ID, can I get more information about the question? (Question text, type, etc.)
I required something similar for users to go and edit their response, take a look here: http://productforums.google.com/forum/#!topic/docs/LSKKCR3VHC8
Copy / paste code below:
function assignEditUrls() {
var form = FormApp.openById('1MonO-uooYhARHsr0xxxxxxxxxxxxxxxxxxxxx');
//enter form ID here
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses');
//Change the sheet name as appropriate
var data = sheet.getDataRange().getValues();
var urlCol = 4; // column number where URL's should be populated; A = 1, B = 2 etc
var responses = form.getResponses();
var timestamps = [], urls = [], resultUrls = [];
for (var i = 0; i < responses.length; i++) {
timestamps.push(responses[i].getTimestamp().setMilliseconds(0));
urls.push(responses[i].getEditResponseUrl());
}
for (var j = 1; j < data.length; j++) {
resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
}
sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);
}
这篇关于如何为Google表单生成预填表单网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!