0

I have a google web application, with the following GAS code. I try to set the global variable sheet for that based on url parameter. But when I call getTableData() from the aHtml code, the sheet is undefined. How to fix that?

const ss = SpreadsheetApp.openById("...abc...");
const sheetA = ss.getSheetByName("A");
const sheetB = ss.getSheetByName("B");

var sheet;

function doGet(e) {
  if(e.parameter.p == "a") return loadA();
  return loadHomePage(e);
}

function loadA() {
  var html = HtmlService.createTemplateFromFile("aHtml");
  sheet = sheetA;
  return html.evaluate();
}

function getTableData() {
  return sheet.getRange(2,1,sheet.getLastRow()-1,9).getValues();;
}
Rubén
  • 29,320
  • 9
  • 61
  • 145
Mottore
  • 9
  • 5
  • 2
    In GAS global variable get reassigned on every function call. I'd recommend that you use PropertiesService for global variables because they remain persistent until you change them again. – Cooper Aug 03 '21 at 15:39

0 Answers0