I am trying to setup a Google Form that will create a 'choose from list' question, with each option being drawn from the rows in a specific column.
I have tried this code, but it has not worked for me at all.
The code that I have so far is below. I am able to create the desired form question with the data from only one row in the specific column (in this case the last row of the column).
If anyone can help by pointing me the right direction as to how to assign each selected row to only one questions option. Also if these is some kind of way to dynamically update the question options every time the spreadsheet is updated.
var idColumn = 1; // ID of the selected column
//gets document ID from spreadsheet
//(not 100% sure the role of all of these lines, have worked it out from other examples of code online)
function spreadSheetGetter() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var lr = rows.getLastRow();
var docId = sheet.getRange(lr,idColumn,1,1).getValue(); //gets the data from the last row in selected column
fillFormData(docId);
}
//fills for with document ID
function fillFormData(docId) {
var form = FormApp.openById('MY FORMS ID');
var item = form.addListItem();
item.setTitle('Select Existing Customer') //creates the choose from list question
.setChoices([
item.createChoice(docId), //data from row 1
item.createChoice(docId) //data from row 2 etc...
])
}