0
votes

Currently using the below app script function to update one column of data into one section of my google form. However, I want to write a code where I can update multiple rows of data into multiple sections of the google form.

Example: Column 1 update to Section 1, Column 2 update to Section 2 and etc..

Google Sheet - Employee Names

function updateForm(){
  // call your form and connect to the drop-down item
  var form = FormApp.openById("Form Id");

  var namesList = form.getItemById("Dropdown List ID").asListItem();


// identify the sheet where the data resides needed to populate the drop-down
  var ss = SpreadsheetApp.getActive();
  var names = ss.getSheetByName("Sheet Name");

  // grab the values in the first column of the sheet - use 2 to skip header row
  var namesValues = names.getRange(2, 10, names.getMaxRows() - 1).getValues();

  var shopperNames = [];

  // convert the array ignoring empty cells
  for(var i = 0; i < namesValues.length; i++)   
    if(namesValues[i][0] != "")
      shopperNames[i] = namesValues[i][0];

  // populate the drop-down with the array data
  namesList.setChoiceValues(shopperNames);

}
1

1 Answers

0
votes

For better organisation, please arrange the data as below

Name - Address

This way you can add new persons easily and change the address easily.

After that, it becomes easy to filter the range by column B and you can easily get the list of persons in the street.

ArrayFormula makes it very easy to do this

https://sites.google.com/site/scriptsexamples/custom-methods/2d-arrays-library