Service Error: Spreadsheets on Google Scripts Service Error: Spreadsheets on Google Scripts json json

Service Error: Spreadsheets on Google Scripts


You can get service errors like this when you access improper ranges, and the error may not be raised until a subsequent access. For example, if you get a Range that references columns that don't exist (like H if you only have A-E), or rows that don't exist (like row 10001 when you only have 10000 rows). This is noted in the Apps Script Issue Tracker: https://issuetracker.google.com/issues/68062620

With regards to the source of your issue, your script is highly unoptimized and does not follow Apps Script "Best Practices" regarding use of the Spreadsheet Service. Namely, you should use batch operations such as Range#setValues operation to write whole blocks, or at least appendRow to append each row (instead of sheet.getRange(rowIndex, someColumn).setValue(oneValue)). These methods will add relevant rows to hold the data if they need to.

An example modification of your code:

var itemFields = [ "name",                   "rarity",                   "price_last_changed",                   "max_offer_unit_price",                   "min_sale_unit_price",                   "offer_availability",                   "sale_availability" ];function addResultPage_(sheet, results) {  const imgs = [],  const data = results.map(function (result, index) {    if (result.img)      imgs.push({row: index, url: result.img});    return itemFields.map(function (field) { return result[field] || ""; });  });  if (!data.length) return;  const startRow = sheet.getLastRow() + 1;  sheet.getRange(startRow, 2, data.length, data[0].length).setValues(data);  if (imgs.length)    imgs.forEach(function (imgInfo) {      sheet.insertImage(imgInfo.url, 1, startRow + imgInfo.row);    });}function listAllItems() {  const sheet = SpreadsheetApp.getActiveSheet(),        totalPages = updateStartStatus("List All Items");  for (var page = 1; page <= totalPages; ++page) {    var pageResults = getItemsByPage(page);    if (pageResults.results)      addResultPage_(sheet, pageResults.results);    else      console.warn({message: "No results for page '" + page + "'", resp: pageResults});  }}


I like what ellockie said - I was (unwittingly) having the same problem. I was trying to range.sort(8), but to collect the range, I used:

sheet.getRange(2,1,sheet.getMaxRows(), sheet.getMaxColumns());

But what I should have used was:

sheet.getRange(2, 1, sheet.getMaxRows()-1, sheet.getMaxColumns());

The error message, as of 5/1/2015, still is very cryptic and offers no further details than the "Service error: Spreadsheets".


Marchello, I've run into the same problem today and have just found an answer to get round it here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=3815 (see #4). The idea is to add rows to the bottom of the sheet that would let the scripts start working again. It does work in my case.