Reputation: 472
I've seen a million things that are similar, but nothing that is actually helpful on this.
I have a Google Sheet with about 900 records. I want to create a Google Form that can import that data and create a checkbox in the Google Form for each GS record. I know App Scripts can do a lot of cool things from researching this, but I haven't found anything close to helpful on making this work.
Has anyone imported GS data to a Google Forms to create checkboxes for GS records?
Upvotes: 0
Views: 1496
Reputation: 2072
It sounds like your question has two parts:
Use the .getValues()
method of the Range class to get spreadsheet data. It would help to know more about the structure of your spreadsheet, but assuming you have a sheet called "Options" and the data you want is in the range A1:A10
of that sheet, you can do this:
// Get question data from the sheet
var sheet = SpreadsheetApp.getActive().getSheetByName('Options')
var choices = sheet.getRange("A1:A10").getValues()
// .getValues() returns a rectangular array, so we want the first (only) value in each row.
.map(function(row){return row[0]})
Now you have an array of data in choices
.
I'm assuming you want to create a new form with this checkbox question. If instead you want to insert the question in an existing form, use FormApp.openById()
or FormApp.openByUrl()
instead of FormApp.create()
// Create the form and add the question item
var form = FormApp.create("{Form Title}")
var item = form.addCheckboxItem()
.setTitle("{Question Title}")
.setChoiceValues(choices)
See the documentation for .addCheckBoxItem()
and .setChoiceValues()
Upvotes: 2