-2

I am testing out array handling with checkboxes and have the following code:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
function arrayTest() { 
  var bigArray = sheet.getRange(1,1,5,3).getValues();
  bigArray[2][1] = false;
  sheet.getRange(1,1,5,3).setValues(bigArray);
}

My sheet looks like this:

small spreadsheet with numbers and checkboxes

The TEST button is assigned to my arrayTest function. When I run it in the IDE, it runs fine. When I click the button on the sheet to run the same code, I get TypeError: Cannot read properties of null (reading 'getRow'). This error message points to a random function elsewhere in the code base, but there's no reason that I can see that that function would be called.

Why do I get a TypeError executing from the sheet?

UPDATE: I created a new project, re-created the sheet and copied in the code, and it worked fine from the button. I don't understand why it was calling a random function, however.

4
  • It's unclear what you mean by the "UPDATE". Does your spreadsheet have more than one project? It's doubtful that a random function was called. You can see which function was called in the execution logs. Commented Nov 12 at 22:43
  • @StuartL Do not include solution to question please (post a separate answer instead). Commented Nov 13 at 20:13
  • @user4157124 The "update" doesn't look as a solution. Commented Nov 13 at 22:37
  • @Wicket It is, which is why it was posted as answer too. The solution was to re-create the sheet. May not have gotten to the root cause of the problem but affirms it "was caused by a typo or a problem that can no longer be reproduced" or otherwise lacks (debugging) details, while explaining what was done to make it work without TypeError. The answer should not have been deleted in LQA review and revision #3 (that also fixed other issues) should not have been rolled back. Commented Nov 16 at 1:33

1 Answer 1

0

TypeError: Cannot read properties of null (reading 'getRow')

The error message indicates that the button doesn't run the arrayTest function but some other function that calls the Range.getRow() method, and the Range object is undefined in that function.

To fix the error, right-click the button and assign the correct function.

In the event you have several script projects bound to the spreadsheet, you may have several functions by the same name, and the function that runs may be different from what you think. Rename functions across script projects so that every function has a unique name. See Which function runs.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.