juliarnasution

google app script

Nov 9th, 2019
14,513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updateForm(){
  2.   // call your form and connect to the drop-down item
  3.   var form = FormApp.openById("Your Form ID");
  4.   var namesList = form.getItemById("The Drop-Down List ID").asListItem();
  5. // identify the sheet where the data resides needed to populate the drop-down
  6.   var ss = SpreadsheetApp.getActive();
  7.   var names = ss.getSheetByName("Name of Sheet in Spreadsheet");
  8.   // grab the values in the first column of the sheet - use 2 to skip header row
  9.   var namesValues = names.getRange(2, 1, names.getMaxRows() - 1).getValues();
  10.   var studentNames = [];
  11.   // convert the array ignoring empty cells
  12.   for(var i = 0; i < namesValues.length; i++)  
  13.     if(namesValues[i][0] != "")
  14.       studentNames[i] = namesValues[i][0];
  15.   // populate the drop-down with the array data
  16.   namesList.setChoiceValues(studentNames);
  17. }
Add Comment
Please, Sign In to add comment