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

295 views
Skip to first unread message

roshan kumar

unread,
Nov 26, 2020, 6:39:09 AM11/26/20
to google-apps-sc...@googlegroups.com
I have a google form where I have a multiple choice question Territory field. This field is having two valid answer 1. United States and 2. Others. When you choose other option you can write down any Country name in text area. 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 workiing. I want to send Others as answer to this question while submitting the form. Can anyone help me out. I am included picture of field and script below for reference .

other.JPG




**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);
  }
  

US.JPG

 
  
  



Alan Wells

unread,
Nov 26, 2020, 8:20:36 AM11/26/20
to Google Apps Script Community
You don't need the "If,Else" code that tests for United States.  Try converting the answer as an array to a string:

var multiChoiceAnswer,territoryfield,territoryresponse;

  multiChoiceAnswer = [[territoryvalue]];

  multiChoiceAnswer = typeof multiChoiceAnswer === 'string' ? multiChoiceAnswer : multiChoiceAnswer.toString();
 
  territoryfield = territory.asMultipleChoiceItem()
  territoryresponse = territoryfield.createResponse([[multiChoiceAnswer]])
  formResponse.withItemResponse(territoryresponse);

roshan kumar

unread,
Nov 26, 2020, 9:14:06 AM11/26/20
to Google Apps Script Community
Hi aj.addons

Thanks for your reply. Can you briefly explain this particular line:

multiChoiceAnswer = typeof multiChoiceAnswer === 'string' ? multiChoiceAnswer : multiChoiceAnswer.toString();


Thanks

Alan Wells

unread,
Nov 26, 2020, 9:21:35 AM11/26/20
to Google Apps Script Community
That line of code is using a JavaScript ternary operator.
See:

It is an "If, then, else" statement without the "If, then, else" key words.
The question mark character is used instead of the "then" keyword.
A colon is used instead of the "else" keyword.
The end result is always that the variable named "multiChoiceAnswer" is assigned a value that is a string.

roshan kumar

unread,
Nov 26, 2020, 9:44:22 AM11/26/20
to Google Apps Script Community
Hi 

Thanks for the reply.

The issue I am facing is- When I am sending United States its working fine. But when I am sending any other Country name its not displaying the answer is form. As per google documentation

Creates a new ItemResponse for this multiple-choice item. Throws an exception if the response argument does not match a valid choice for this item, unless showOtherOption(enabled) is set to true.
 
So I have turner the showotheroption as true. But still if I am sending any other value its not showing up in form.

On Thursday, November 26, 2020 at 6:50:36 PM UTC+5:30, aj.addons wrote:

Alan Wells

unread,
Nov 26, 2020, 10:07:51 AM11/26/20
to Google Apps Script Community
Thanks for confirming the problem that you are experiencing.
I have experienced this problem also, but did not investigate it further.
I think that it's a good possibility that this is a bug.
The documentation states that it should work, but it's not working.
If we have established that there is nothing wrong with the way that the code is written,
then the only thing left to assume is that it is a bug that Google needs to fix.
In that case, we can refer to the Issue Tracker and see if someone has filed a complaint.
I did a search on the Issue Tracker at:

And didn't find any open issues.
I you would like, we can work together to create a new issue.
It needs to be worded well, with a good way to reproduce the issue in order to get any help.

roshan kumar

unread,
Nov 27, 2020, 6:25:26 AM11/27/20
to Google Apps Script Community

Alan Wells

unread,
Nov 27, 2020, 7:59:30 AM11/27/20
to Google Apps Script Community
Thank you for creating a new issue.
I have "stared" the issue, and you should also click the star at the upper left.
A response has come back, and they were able to reproduce the issue, so that's the most important thing.
It will be a great improvement to have this functionality working.
Reply all
Reply to author
Forward
0 new messages