Skip to content

google.script.run problem on Google Apps Script

I am working on a Google Apps Script project, and I have made a html form that will automatically paste the user answers in a sheet.

My problem is the following: I need to add elements in a drop down list with a separated form. To do this, I have made a function that will read some cells and add their value in a “list”. I joined that list to return a string named listVlans.

This is my GS:

function returnList() {
  let ss = SpreadsheetApp.getActive();
  let VLANS = ss.getSheetByName("VLANS");
  let list = VLANS.getRange(3, 9, VLANS.getLastRow() - 2, 1).getValues();
  let listVlans = list.join();
  return listVlans;
}

There is no problem here, it returns a big string (listVlans) with all the elements of my list separated by ,.

My problem is that I would like to import this listVlans from the .gs to my html script to actualize my drop down list elements in function of my sheet’s values.

<script>
    function getList()
    {
      let newList = google.script.run.returnList();
      console.log(newList);
    }
</script>

The problem is that the console.log(newList) is just printing undefined, but it should print my big joined string…

Have you had this problem? Thank you.

Answer

Welcome Thibaud, the problem is not here, you have to evaluate your form by a script included in gs like this one (change names as necessary, inside this script)

function lister() {
  const html = HtmlService
    .createTemplateFromFile('formList')
    .evaluate();
  SpreadsheetApp.getUi().showModelessDialog(html, 'Lister ...');
}