简体   繁体   中英

Fill Google form using Google Apps Script

I just tried my coding below...but the problem is, my google apps script just submit the form with blank value for both "short answer" field. Can someone show me somelight how i can solve my problem. TQ.

function myFunction() {
  var dapatkanForm = FormApp.openByUrl('https://docs.google.com/forms/d/1S1F3cKMwkXm3gVt00RegQ-GCzRfELOq74IH9WEk8SlU/edit?usp=sharing');
  var nama = dapatkanForm.getTitle();
  var listIsiText = dapatkanForm.getItems(FormApp.ItemType.TEXT);
  var panjangArray = listIsiText.length;
  for(var i=0; i<panjangArray; i++)
  {
    var textTemp = listIsiText[i];
    var nakSet = textTemp.asTextItem();
    var response = nakSet.createResponse('MOHD ANIS BIN AZINAN');
  }
  var formResponse = dapatkanForm.createResponse();
  formResponse.submit();
  Logger.log(nama);
}

Your code is very close to the solution. You just need one additional method. The following line…:

var formResponse = dapatkanForm.createResponse();

…should end up looking like:

var formResponse = dapatkanForm.createResponse().withItemResponse(response);

By using .withItemResponse() the form submit will upload your responses instead of being void. Please, ask me for more clarifications if you still need help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM