I am using a script to push my AdWords ad performance to a Google sheet. Google has created a standard template and even the standard template is throwing an error.
https://developers.google.com/adwords/scripts/docs/solutions/ad-performance. Here is the error: TypeError: Cannot call method "getRange" of null. It seems as if, after a period of time, the script can no longer find the last row to place new data.
// what column should we be looking at to check whether the row is empty?
this.findEmptyRow = function(minRow, column) {
var values = this.sheet.getRange(minRow, column,
this.sheet.getMaxRows(), 1).getValues();
for (var i = 0; i < values.length; i++) {
if (!values[i][0]) {
return i + minRow;
}
}
return -1;
};
this.addRows = function(howMany) {
this.sheet.insertRowsAfter(this.sheet.getMaxRows(), howMany);
};
this.writeRows = function(rows, startRow, startColumn) {
this.sheet.getRange(startRow, startColumn, rows.length, rows[0].length).
setValues(rows);
};
}
Any ideas how I can repair this script? Ideally, the script should be able to determine which row to place the data on an ongoing basis. Note, if the spread sheet is empty usually I have no issue getting the script to work, this error only appears to occur after a period of time.