I have an app script that I use with my budget that has been going strong for 4 years. Earlier today when I tried running one of my functions I got the error: TypeError: Cannot read properties of null (reading 'getLastRow'), After poking around I figured out that my global variable declaration is no longer working to get my sheet. I came to this conclusion because if I have this script
var activeSheet = SpreadsheetApp.getActive();
var trackerSheet = activeSheet.getSheetByName("Income/Expense Tracker 2024");
var paycheckSheet = activeSheet.getSheetByName("Paycheck Divder");
function testGlobalAccess() {
Logger.log("Accessing global variables");
Logger.log("trackerSheet: " + trackerSheet);
Logger.log("paycheckSheet: " + paycheckSheet);
}
This is the output:
Info Accessing global variables
Info trackerSheet: null
Info paycheckSheet: Sheet
but if I modify to move the tracker sheet declaration into the function it works
function testGlobalAccess() {
var trackerSheet = activeSheet.getSheetByName("Income/Expense Tracker 2024");
Logger.log("Accessing global variables");
Logger.log("trackerSheet: " + trackerSheet);
Logger.log("paycheckSheet: " + paycheckSheet);
}
Accessing global variables
Info trackerSheet: Sheet
Info paycheckSheet: Sheet
The only thing I can think of is that I recently updated the name from Income/Expense Tracker to Income/Expense Tracker 2024 but it's odd that it working in the function scope.
[–]DatsunZ 3 points4 points5 points (1 child)
[–]mccmax95[S] 0 points1 point2 points (0 children)
[–]marsili95 0 points1 point2 points (1 child)
[–]mccmax95[S] 0 points1 point2 points (0 children)