0

I am running a script to check for the last number and get a value to move up by one. I have done a similar code before without issues, but for some reason I am getting errors on checking if the first portion is running correctly. I have check that the SheetName is correct. Here is a copy of the simple code

function generateEmpID() {

SpreadsheetApp.getActiveSpreadsheet().getSheetByName("EmpID").getRange(2,1).getValue();

console.log(SpreadsheetApp.getActiveSpreadsheet().getSheetByName("EmpID").getRange(2,1).getValue());
  
}

And this is the response I get:

12:01:35 PM Notice Execution started
12:01:36 PM Error TypeError: Cannot read property 'getSheetByName' of null generateEmpID @ Code.gs:3

New contributor
Brian Kitching is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • 2
    Welcome to Web Applications Stack Exchange. The error message suggests that you are running the function in a context where there is no active document. There are many such contexts. Please describe how you are running the function. Nov 22 at 11:17