Reputation: 5770
I have a Google Form that is a simple checkbox list with an "Other" option. As author of the form it looks like this:
when I fill out the form, I can check the "Other" checkbox and type in a value, and submit.
but when my Google Apps Script runs,
var choices = checkboxItem.getChoices();
Logger.log("Choices array length: %s", choices.length);
var results = [];
for (var i = 0; i < choices.length; ++i) {
results.push(choices[i].getValue());
}
Logger.log("getFormChoicesAsStrings %s", JSON.stringify(results));
it isn't seeing what I typed in for the "Other" value (in this example: "Steve Jobs"), as evidenced by the log output:
[19-01-12 20:31:59:164 PST] Logger.log([Choices array length: %s, [1.0]]) [0 seconds]
[19-01-12 20:31:59:165 PST] Logger.log([getFormChoicesAsStrings %s, [["John Doe"]]]) [0 seconds]
The API for CheckboxItem allows a true/false whether or not an Other option is displayed, and the API for Choice doesn't offer anything around the Other option.
What API call can I do to read the value of the Other option?
Upvotes: 2
Views: 264
Reputation: 201378
If my understanding is correct, how about this modification?
Please copy and paste the following script and install the trigger for myFunction()
.
// FormApp.getActiveForm() // This is used for adding a scope of https://www.googleapis.com/auth/forms
function myFunction(obj) {
var r = obj.response.getItemResponses();
r.forEach(function(e) {
var r1 = e.getItem().getTitle();
var r2 = e.getResponse();
Logger.log(r1); // "Who attended?"
Logger.log(r2); // ["John Doe","Steve Jobs"]
});
}
myFunction()
as a Installable Triggers.
If I misunderstand your question, please tell me. I would like to modify it.
Upvotes: 1