Submit form via google scripts

I need to submit the form in google script, but get this error:

TypeError: cannot call method "withItemResponse" from undefined

According to the link below, here is how it should be configured https://developers.google.com/apps-script/reference/forms/form#createResponse ()

the code:

 //Submit form

  var formID = row[24]; 

  var form = FormApp.openById(formID);
  Logger.log(form.getId());  //returns correct ID
  form.createResponse() ;
  form.FormResponse.withItemResponse('Core Teachers', logSummary);  
  //form has only two questions, a short text and a paragraph text
    form.FormResponse.submit(); 
+4
source share
1 answer

form.createResponse()returns FormResponsewhich you need to assign to the variable.

also withItemResponse()expects an object of type ItemResponse. I am not familiar with Google forms, but maybe this will help you in the right direction:

var formID = row[24]; 
var form = FormApp.openById(formID);
var formResponse = form.createResponse();
// get items of form and loop through
var items = form.getItems();
for (index = 0; index < a.length; ++index) {
  var item = items[index]
  // Cast the generic item to the text-item class. You will likely have to adjust this part. You can find the item classes in the documentation. https://developers.google.com/apps-script/reference/forms/item-type.
  if (item.getType() == 'TEXT') {
    var textItem = item.asTextItem();
    var itemresponse = textItem.createResponse('Core Teachers');
    formResponse.withItemResponse(itemresponse);  
  }
}
formResponse.submit();

, - , , String Boolean, , createResponse. , GoogleAppsScript .

+3

Source: https://habr.com/ru/post/1678058/


All Articles