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
1.0k views
in Technique[技术] by (71.8m points)

google apps script - create an ItemResponse in Form

I'm trying to send an automatic response from code to a form of mine. I can open it and send empty responses (I create a FormResponse and submit it empty).

Now I want to fill the itemResponses prior to submit. I'm trying to use

FormResponse.withItemResponse(itemResponse)

https://developers.google.com/apps-script/reference/forms/form-response?hl=es-ES#withItemResponse(ItemResponse) but I can't find a way to create the ItemResponse argument to fill my FormResponse. I searched the whole documentation, I know there must be a way, but I simply can't find it.

var form = FormApp.getActiveForm();
var response = form.createResponse();
var itemResponse = ????????????;
response.withItemResponse(itemResponse);
response.submit();

Any hint? Thank you!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Found it!

Because Google search "itemresponse" throw me nothing, I finally searched itemresponse in Google for the GAS documentation site...

The only way to create an ItemResponse is from the specific Item typed object. For example:

var itemResponse = TextItem.createResponse('my text');

https://developers.google.com/apps-script/reference/forms/text-item#createResponse(String)


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

...