getSheetByName() timeout

358 views
Skip to first unread message

Ross Crawford

unread,
Jun 3, 2022, 1:33:14 AM6/3/22
to Google Apps Script Community
Hi, I have a script that has been working fine by suddenly is getting timeouts. I've narrowed it down to the following simple code:

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var doc = ss.getSheetByName("Sheet name");

When I debug, the first line works fine, but the 2nd line never completes, and times out after 5 minutes. Nothing in the sheet has changed as far as I can see, what would cause this?

Thanks in advance.

Ross Crawford

unread,
Jun 3, 2022, 1:59:40 AM6/3/22
to Google Apps Script Community
Even var ns = ss.getNumSheets(); times out. Could this be a corruption in my sheet? It opens fine in google docs, and all the data looks right.

Clark Lind

unread,
Jun 6, 2022, 12:49:26 AM6/6/22
to Google Apps Script Community
Make sure the script is authorized. Add this simple function, then debug it:

function authorized() {
  console.log("I am authorized")

Moises Chavez

unread,
Aug 12, 2022, 1:17:39 AM8/12/22
to Google Apps Script Community
Hey, having the same issue with one of my "bulky" reports. For some reason, any script times out, even the smallest of things. I don't have issues on other reports. 

Did you manage to find out the issue in your end? 

Bayu Anandavi

unread,
Sep 20, 2022, 12:08:24 AM9/20/22
to Google Apps Script Community
I have the same issue with "getSheetByName" function. It always timed out. Did you managed to resolve it?

Ross Crawford

unread,
Sep 20, 2022, 3:12:42 AM9/20/22
to Google Apps Script Community
Hi, yes I resolved it by moving all my calculations to a separate spreadsheet and copying data to it using IMPORTRANGE(). Apparently calling  getSheetByName seems to cause the sheet to refresh all the calculated cells.

Andrew Brown

unread,
Sep 20, 2022, 3:49:23 AM9/20/22
to google-apps-sc...@googlegroups.com
HI,

I use:

const sn = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();

Regards,

Andrew J Brown


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/84fbb6c2-dda0-46d7-ad45-f56be4762ed1n%40googlegroups.com.

Ross Crawford

unread,
Sep 21, 2022, 2:16:49 AM9/21/22
to Google Apps Script Community
Thanks, but that is doing the opposite of what this discussion is about. We are returning a spreadsheet reference given it's name.

Dmitry Kresin

unread,
Dec 17, 2022, 9:56:05 AM12/17/22
to Google Apps Script Community
I have the same issue with the same two lines of code. Everything worked fine for weeks and now it just stops working without any errors.  getSheetByName simply times out, it never ends. Did anybody find the solution? Do you need to buy a google suite account to avoid this kind of issues?

Robin Kowalski

unread,
Sep 11, 2023, 8:54:35 AM9/11/23
to Google Apps Script Community
Hi,

Like Dmitry, I have the same issue. Everything worked fine until this morning. Does anyone have a solution ?

cbmserv...@gmail.com

unread,
Sep 11, 2023, 2:42:43 PM9/11/23
to google-apps-sc...@googlegroups.com

This may be a corrupted spreadsheet. I would try to create a new spreadsheet and copy over any data to it and then link the script to the new sheet.

 

I have seen this before and the corruption I had seen was more how the scripts were linked to the sheets.

--

You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Zach Davis

unread,
Sep 14, 2023, 7:09:12 PM9/14/23
to Google Apps Script Community
Seeing this same issue. Did anyone find a solution? I already offloaded my calculations and still no luck.

Valeriu

unread,
Sep 15, 2023, 3:10:49 AM9/15/23
to Google Apps Script Community
Same issue here with a spreadsheet with many calculations. When I remove the sheets with calculations, the script seems to be working fine.

cwl...@gmail.com

unread,
Sep 15, 2023, 9:30:03 AM9/15/23
to Google Apps Script Community
Has anyone tried adding a "spreadsheet.flush()" so it doesn't get bogged down updating the calculated content? If you have a bunch of calculations, prior to trying to grab a sheet (e.g., getSheetByName() ), insert a flush statement right before you attempt to get the sheet. I haven't tested it, but that is what I would try.

Valeriu

unread,
Sep 15, 2023, 1:10:40 PM9/15/23
to Google Apps Script Community
I just tried using Spreadsheet.flush() before the getSheetByName and it doesn't help.

Todd Wolford

unread,
Sep 15, 2023, 10:25:14 PM9/15/23
to Google Apps Script Community

Maybe try 

var ss = SpreadsheetApp.getActive()
ss.setIterativeCalculationEnabled(false)

//do your thing

ss.setIterativeCalculationEnabled(true)

Not tested- just a suggestion of something to try...

Valeriu

unread,
Sep 16, 2023, 4:09:49 AM9/16/23
to Google Apps Script Community
I tried using 
ss.setIterativeCalculationEnabled(false)
but it freezes at this line.
Reply all
Reply to author
Forward
0 new messages