Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheet Error: Service Spreadsheets timed out while accessing document with id

I get this error "Service Spreadsheets timed out while accessing document with id ..." every time I run a very simple code, in which I am basically copying data from one google sheet to another using getValues() and setValues().

I don't think it is because of 5M cells limit, because the same exact function is working perfectly fine in another Google Sheet with even bigger size. So I really don't understand where the problem is.

I have tried to create an empty GS and run the function, so I am only pulling data without any other calculation, but still, it gives me the same error.

Any idea what the reason could be?

Here the code as reference:

   function MyFunction(){
      var pm_ss_0 = SpreadsheetApp.openById('...');
      var pm_tab_0 = pm_ss_0.getSheetByName('...');
      var pm_data_0 = pm_tab_0.getDataRange().getValues();
      var target_ss_0 = SpreadsheetApp.getActiveSpreadsheet();
      var target_tab_0 = target_ss_0.getSheetByName('...');
      target_tab_0.clearContents();
      var target_data_0 = target_tab_0.getRange(1, 1, pm_data_0.length,   
      pm_data_0[0].length).setValues(pm_data_0);
      }
like image 509
cate Avatar asked Oct 26 '20 10:10

cate


3 Answers

This issue has also been reported on Google's Issue tracker

Go there and star the issue so you get the updates on it.

like image 122
Kessy Avatar answered Nov 15 '22 08:11

Kessy


I solved the issue inserting a flush before and after the line where the error appeared.

SpreadsheetApp.flush();
ss.insertSheet("Report "+fogl.getName(), ss.getNumSheets()); //line with the error in my code
SpreadsheetApp.flush();

like image 40
Da Ni Avatar answered Nov 15 '22 07:11

Da Ni


This problem is more random than 95% of the commentary on the Web about it attests to. I just had this happen to me for the first time, and it even affected a Macro that did absolutely nothing but hide the Active Tab. I couldn't do anything with Script Editor.

I tried simply duplicating the document. BION, that was the end of the problem for me. Or at least, so far.

like image 36
Atiq Zabinski Avatar answered Nov 15 '22 09:11

Atiq Zabinski