2
votes

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

1 Answers

9
votes

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();