A Google spreadsheet form that fills out forms based on a spreadsheet.

I need to find a way to have several choices in changing the shape of Google based on a set of cells in a Google spreadsheet that is constantly changing. Any ideas?

+15
source share
2 answers

The requested function does not exist. A feature request related to linking Google forms to spreadsheets would be the best choice for synchronizing the two.

It is always possible to create a form using URL parameters, as described here: https://docs.google.com/support/bin/answer.py?hl=en&answer=160000

0
source

. script , . script, - Google script. script. script .

function updateForm(){
  // a way to get the items from the form
  var form = FormApp.openById("<your form id>");
  var agentList = form.getItemById(<your item id>).asListItem();
  var hotelList = form.getItemById(<your item id>).asListItem();


  var ss = SpreadsheetApp.getActive();
  var agents = ss.getSheetByName("Agents");
  var hotels = ss.getSheetByName("Hotels");

  // get the values in the first column accept header row 1
  var agentValues = agents.getRange(2, 1, agents.getMaxRows() - 1).getValues();
  var hotelValues = hotels.getRange(2, 1, hotels.getMaxRows() - 1).getValues();

  var agentNames = [];
  var hotelNames = [];

  // convert 2D to 1D array and ignore empty cells
  for(var i = 0; i < agentValues.length; i++) {  
    if(agentValues[i][0] != "") {
      agentNames[i] = agentValues[i][0];
    }
  }

  for(var i = 0; i < hotelValues.length; i++) {
    if(hotelValues[i][0] != "") {
      hotelNames[i] = hotelValues[i][0];
    }
  }

  // populate the list
  agentList.setChoiceValues(agentNames);
  hotelList.setChoiceValues(hotelNames);
}

/ , .

+21

Source: https://habr.com/ru/post/1589347/


All Articles