我可以通过Google apps脚本填写TextItem吗? [英] Can I fill in TextItem by Google apps script?
问题描述
我可以运行Session.getEffectiveUser()。getEmail()给被调查者电子邮件地址。但我不能在文本框中填写以帮助他们。我可以用Google App Script做这样的事情吗?
我认为我找到了解决方案。但我必须承认这并不明显。在应用程序脚本文档中,您可以创建一个预先填写的网址。
但是,您需要有一个 ItemResponse 元素,并且我没有找到任何解释来构建一个。诀窍是当你有一个 item 时,如果你将它作为一个定义的类型 asTextItem(),你可以从它获得一个 ItemResponse 。
理解它的最佳方法是观察下面的代码:
$ p $函数getPreFilledItem() {
var form = FormApp.openById(YOUR_FORM_ID);
var items = form.getItems();
var itemOfInterest;
for(var i in items){
if(items [i] .getTitle()==YOUR_QUESTION_TITLE){
itemOfInterest = items [i];
Logger.log(
form.createResponse()。
withItemResponse(itemOfInterest.asTextItem()。createResponse(PREFILLED_TEXT))。
toPrefilledUrl()
);
}
希望这能帮助你,
Harold
I made a form with Google Form Builder, then I add a script for it.
I can run Session.getEffectiveUser().getEmail() to the respondent's email address. but I cant fill it in the textbox to assist them. Can I do such thing with Google App Script?
I think I found a solution to your problem. But I must admit it was not evident.
In apps scripts documentation you've got everything to create a prefilled url.
BUT for that you need to have a ItemResponse element and I didn't found any explaination to build one. The trick is when you've got an item you can get a ItemResponse from it if you get it as a defined type "asTextItem()".
Best way to understand it, is to watch the code below:
function getPreFilledItem(){
var form = FormApp.openById("YOUR_FORM_ID");
var items = form.getItems();
var itemOfInterest;
for(var i in items){
if(items[i].getTitle()=="YOUR_QUESTION_TITLE"){
itemOfInterest=items[i];
}
}
Logger.log(
form.createResponse().
withItemResponse(itemOfInterest.asTextItem().createResponse("PREFILLED_TEXT")).
toPrefilledUrl()
);
}
Hoping this will help you,
Harold
这篇关于我可以通过Google apps脚本填写TextItem吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!