0

I'm trying to create a budgetting file in Google Sheets that my collegues can make a copy of and then use it for their specific project. With this copy I want to keep my original protected sheets with me as an owner and the only one who can change them (if they just copy the file, they become the file-owner and are then able to change my blocked cells).

I found a code that should do this, but it gives me this error: Exception: Unexpected error while getting the method or property getFileById on object DriveApp. Does any know how to fix this?

What I Did: I've added scopes to the manifest file (appscript.json). Which looks like this:

{
  "timeZone": "Europe/Brussels",
  "dependencies": {
       "enabledAdvancedServices": [
      {
        "userSymbol": "Sheets",
        "version": "v4",
        "serviceId": "sheets"
      }
    ]
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
   "oauthScopes": [
          "https://www.googleapis.com/auth/spreadsheets", 
          "https://www.googleapis.com/auth/drive"
   ]
}

And the first bit of code (with the property getFileById in it) is:

function Main() {
  var template = DriveApp.getFileById('1839156158');              
  var destination = DriveApp.getFolderById('1ajqwefqcjwefjipqjpo11');  
  var curDate = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "yyyy-MM-dd");
  var copyName = '[NAME FESTIVAL]' + template.getName() + curDate;                  

  copyTemplate(template, copyName, destination);
}
Jody
  • 1
  • 1
  • About `1839156158` of `DriveApp.getFileById('1839156158');`, is that a valid Spreadsheet ID of Spreadsheet you can access? – Tanaike Apr 17 '23 at 11:54
  • Hi @Tanaike , yess that was my thoughts first too, but I am the owner/builder and it this part of the URL of the sheet: **.../editgid=1839156158** – Jody Apr 17 '23 at 12:04
  • Thank you for replying. From `that was my thoughts first too, but I am the owner/builder and it this part of the URL of the sheet: .../edit#gid=0000011`, I think that in this case, your Spreadsheet ID is not correct. The Spreadsheet ID is `{spreadsheetID}` of `https://docs.google.com/spreadsheets/d/{spreadsheetID}/edit#gid={sheetId}`. [Ref](https://developers.google.com/sheets/api/guides/concepts) From your reply, it seems that you are using the Sheet ID as the Spreadsheet ID. I thought that this might be the reason for your current issue. Please confirm it again. – Tanaike Apr 17 '23 at 12:06
  • I thought that this thread might be an answer to your question. https://stackoverflow.com/q/36061433 – Tanaike Apr 17 '23 at 12:07
  • @Tanaike Yes ofcourse, thank you so much! Dumb mistake from my side... thank you! – Jody Apr 17 '23 at 12:08

0 Answers0