There is something wrong, maybe a bug, but this fails randomly. Anyway here is a super simple demo of about "how to get this working"
- Create a spreadsheet
- Add some values to a row
- Select the row
- The following script to a bounded project to the previous spreadsheet
function myFunction() {
var values = SpreadsheetApp.getActiveRange().getValues();
Logger.log(values);
}
- Authorize the script
- Run the function.

[20-08-08 15:58:57:727 CDT] [[adfa, afdfafs, dasfasf, , , , , , , , , , , , , , , , , , , , , , , ]]

I think that there is a bug related to use chaining with getActiveRange()
.
This sometime fails to get the expected result
function myFunction2(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var values = sheet.getActiveRange().getValues();
Logger.log(values);
}
NOTE: The following snapshots were taken from the script's executions page.
Failed

Succeded

This gets the expected result
function myFunction3(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var range = sheet.getActiveRange();
var values = range.getValues();
Logger.log(values);
}
Related
The following are questions that uses Class Sheet getActiveRange()
chained with some Class Range methods like getRow()
, getValues()
but the current answers doesn't mention the cause of the problem, they just offer an alternative code