2

In my company we use a team drive, where we store a template spreadsheet which our API server copies a lot of times. The spreadsheet contains a few custom Google App Script functions which should be copied as well.

Right now when the API copies the spreadsheet, the scripts stop working in the copy. According to this issue https://issuetracker.google.com/issues/36762799 , service accounts can't execute scripts. However, in a Team Drive there are no owners. I even checked the permissions with Permissions.List from the Drive API and I can see that everyone is an organizer and the API does not allow me to specify another user as an owner, but the scripts still won't work (Error: Please try saving the project again). On the other hand, if I go and copy the generated sheet by hand, scripts execute just fine.

I tried moving everything to an add-on, however to my displeasure, it appears that service account-owned files can't execute add-on scripts as well (if the file is created by the bot, custom function names simply fail to resolve).

Does anyone know of a way to deal with this situation? Is there a more elegant solution besides using an actual account for the copying if that's even possible to do programmatically?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Stealthmate
  • 147
  • 9
  • Try to play with available functions in the [GAS Spreadsheet Services documentation](https://developers.google.com/apps-script/reference/spreadsheet/). Under [Class Spreadsheet](https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet), you may want to use the [copy](https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#copy(String)) method. It copies the spreadsheet and returns the new one. – MαπμQμαπkγVπ.0 Jul 20 '18 at 11:25
  • In your situation, is this thread useful? https://stackoverflow.com/q/70367955/7108653 – Tanaike Jan 01 '22 at 01:24

0 Answers0