Creating Forms using script
In Chapter 1, Introducing Google Apps Scripts, you created a Form manually, but this time we will create Forms programmatically by script. First of all, we will create a Form with four choices and an Other option choice. For simplicity, we add places as a multiple choice radio group. Each choice is exclusively selectable. Create the function createForm
as shown here in a spreadsheet code file:
function createForm() { var places = ["Place 1","Place 2","Place 3","Place 4"]; var form = FormApp.create("Vacation Form"); form.addMultipleChoiceItem() .setTitle('Where will you go for vacation?') .setChoiceValues(places) .showOtherOption(true); }
The places
variable holds a few random places, and you can assign any place name and any number of places as an array of strings. The create
method of FormApp
class creates a form titled Vacation Form
in your Drive's root folder (My Drive
). On running the function, the created Form will look like this...