Narley Brittes
Narley Brittes

Reputation: 151

Adding new item to a listItem (drop down list) on google Forms using apps script

Is there a way to add a new item to a listItem (drop down list) in the new Google Forms using apps script?

I have a google form which has a listItem with many choices:

EX.: Your color - red - blue - white - green

I would like to be able to add a new choice, say "black", to this list using apps script. I know it's possible to add it directly on the form, but the use case needs the choice to be added via apps script.

I tried to use the setChoices() function but this will override the current list with the new choice. I would like to add/append the new choice to the list.

Do you guys know a way to achieve this?

Cheers.

Upvotes: 1

Views: 3593

Answers (1)

mike
mike

Reputation: 7177

Use getChoices() to get a copy of the existing list and append the choice.

choices = listItem.getChoices();
choices.push(listItem.createChoice('black'));
listitem.setChoices(choices);

Upvotes: 2

Related Questions