Reputation: 69
I am trying to fill a Google Form multiple choice with a row of data from a Google Sheet. I can get the row text into an Array, but somehow when I use the method .setChoiceValues(), I get a:
Exception: Invalid conversion for item type: TEXT. (line 36, file "PopulateBudgetCategories")
According to Google documentation, such method receives a String[], but fails, throwing the same expection, even with the following code:
studentNames = ['🚗⛽ Car', '🚑 Healthcare', '📱 Mobile phones'];
formExpenseTypes.asListItem().setChoiceValues(studentNames);
Has anyone got an idea of how to fix this?
Thanks.
Upvotes: 0
Views: 630
Reputation: 69
sorry it was all a mistake by me. In one of hte edits I think the form control's ID's changed order and I was actually trying to add Choices to a Text question.
Upvotes: 0
Reputation: 26796
formExpenseTypes
is an item of type TEXT
asListItem()
means that you are retrieving an item as a dropdown question, however if your question was not a dropdown question when you created it asMultipleChoiceItem()
, not as asListItem()
Sample:
function myFunction() {
var form = FormApp.getActiveForm();
form.addMultipleChoiceItem();
var items = form.getItems();
var formExpenseTypes = items[items.length-1];
studentNames = ['🚗⛽ Car', '🚑 Healthcare', '📱 Mobile phones'];
formExpenseTypes.asMultipleChoiceItem().setChoiceValues(studentNames);
}
Upvotes: 1