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();;
}