Google form Multiple Choice "Other" option not visible when submitted from app script

27 views
Skip to first unread message

roshan kumar

unread,
Nov 26, 2020, 8:18:44 AM11/26/20
to Google Apps Script Community

I have a google form where I have a multiple choice question "Territory field". This field is having two valid answer

  1. 1.United States and
  2. 2. Others (When you choose other option you can write down any Country name in text area) 

other.JPG



  1. Now I am trying to submit this form using google app script. While submitting from app script if I am sending answer to this multiple choice question as "United States" its working. I want to send Others as answer to this question while submitting the form. Can anyone help me out. I am including picture of field and script below for reference .

I am trying to submit this form using google script (part of script mentioned below).

  var formID = "xxxxxxxxxxxxxxxxxxxxxx";
  var Formobj= FormApp.openById(formID);
  var formResponse = Formobj.createResponse();
  var items = Formobj.getItems();
  var territory =  items[1]
  var territoryvalue = "United States"
  
  if (territoryvalue.indexOf("United States") !== -1)
  {
  var territoryfield = territory.asMultipleChoiceItem()
  var territoryresponse = territoryfield .createResponse([["United States"]])
  formResponse.withItemResponse(territoryresponse);
  }
Field value after form is submitted with United states as answer

US.JPG



Clark Lind

unread,
Nov 27, 2020, 12:15:48 PM11/27/20
to Google Apps Script Community
Assuming the rest of your code is valid, I would pass the option you want to send to the function when you call it (either "United States" or "Other...."). Something like this:

//originating function
function parentFunction() {
   some code... 
   sendForm( option )  //either "United States" or "Other..." based on whatever logic you are using 
}

//then wrap this in a function:
function sendForm( option) {

var formID = "xxxxxxxxxxxxxxxxxxxxxx";
  var Formobj= FormApp.openById(formID);
  var formResponse = Formobj.createResponse();
  var items = Formobj.getItems();
  var territory =  items[1];                       
  var territoryvalue = "United States"
  
  if (territoryvalue.indexOf("United States") !== -1)  
  {
  var territoryfield = territory.asMultipleChoiceItem()
  var territoryresponse = territoryfield .createResponse([[option]])
  formResponse.withItemResponse(territoryresponse);
Reply all
Reply to author
Forward
0 new messages