Issue with Maximum time on Script

24 views
Skip to first unread message

Bernard Chu

unread,
Mar 29, 2023, 11:29:44 PM3/29/23
to Google Apps Script Community
Hello~ I honestly don't know how to ask this, so I'll just post what my issue is.

I have a script that copies a page, renames it, and then copies the protections from one specific page. However, the script is now taking longer than 6 minutes to finish and exceeds maximum time.

here is my script:

function copyWithProtections(){
  const sh = SpreadsheetApp.getActiveSpreadsheet();
  const ss = sh.getSheetByName("2");
  const prot = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE)

  let nSheet = ss.copyTo(sh).setName(sh.getNumSheets()-10);

  let p;

  for (let i in prot){
    p = nSheet.getRange(prot[i].getRange().getA1Notation()).protect();
    p.removeEditors(p.getEditors());
    if (p.canDomainEdit()){
      p.setDomainEdit(false);
    }
  }
}


Completion of protections vary due to server speed. I have reduced the max amount of protections in hopes of completion. 

Any suggestions?

Brett Grear

unread,
Mar 30, 2023, 5:12:53 PM3/30/23
to Google Apps Script Community
Are there many protections? This doesn't look like it should take any where near 6 minutes.  Are you sure Google's Servers weren't having a moment at the time.  Have you tried running since?

Kyle Holdridge

unread,
Apr 1, 2023, 12:04:54 AM4/1/23
to google-apps-sc...@googlegroups.com
Have you tried having ChatGPT writing your code for you?
If not try it out. Its free but the $20 a month version is quite a bit smarter. 



--
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/14347957-a3b0-49f1-8d63-a7b6af5b9d95n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages