how to create a google form response with app script

岁酱吖の 提交于 2021-02-07 04:14:40

问题


As a way of initializing a form record, I want to fill and submit a google form with apps script. The key bit of documentation for form.createResponse() is this

Creates a new response to the form. To answer a question item, create an ItemResponse from the item, then attach it to this form response by calling FormResponse.withItemResponse(response). To save the assembled response, call FormResponse.submit().

do I need to new FormResponse() or how do I make this happen?


回答1:


create new form

    var test_form = FormApp.create('test1');
    test_form.addTextItem();

get the first question as a text item

    var questions = test_form.getItems();
    var qt = questions[0].asTextItem();

set the response

    var qr = qt.createResponse('cats');

create and submit a response object

    var FormResponse = test_form.createResponse();
    FormResponse.withItemResponse( qr );
    FormResponse.submit();


来源:https://stackoverflow.com/questions/36831901/how-to-create-a-google-form-response-with-app-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!