7

We are developing a program that uses Google spreadsheets as the input. The values of the spreadsheet is read, processed and a result is showed in a webpage.

When an user sign up we clone a spreadsheet from a template using a service account. The template has some scripts we want to use to help the user to introduce the values on the spreadsheet.

But the scripts seems to have as the owner the service account, and according to Google scripts belonging to service accounts can not be executed.

The error message is :

Google Apps Script: The script cannot be run because it is owned by a service account. Please copy or transfer the project to a valid account before running.

We transfer the ownership of the spreadsheet from the service account to a gmail user, and if that user creates an script it runs perfectly, but the scripts inherited from the template seems to still has as owner the service account and therefore can not been executed.

My question is ... how exactly can I transfer the ownership of a project (a script) from the service account to another user?

I've googled it and searched on the developer Google spreadsheet site but couldn't find an answer

Rubén
  • 24,097
  • 9
  • 55
  • 116
razonasistemas
  • 349
  • 1
  • 4
  • 8
  • Is the script in the spreadsheet? It seems like the script is not attached to the spreadsheet itself and the problem is with the script file itself belonging to the service account. If you have a Google Apps Script file then transfer the ownership of that file to a Google account. Or better yet, if it is started from a web app, make sure you set it to execute **as user accessing the web app** (usually it defaults to **me**) – Vytautas Oct 06 '16 at 08:26
  • @Vytautas I created the script on the template by opening Tools | Script Editor | Create a new project, so I always thing that the script was attached to the spreadsheet. I think the problem is that cloning from the template creates a new spreadsheet where the script belongs to the service account. As I don't know how to transfer the ownership of a script project to a google account, I'm stuck. – razonasistemas Oct 06 '16 at 09:38
  • How does the user start the script? Is it by running it from a web app or do they open the spreadsheet and run it from there? – Vytautas Oct 06 '16 at 12:10
  • @Vytautas The user opens the spreadsheet and then the script should run – razonasistemas Oct 07 '16 at 14:37
  • Wouldn't you have problems with the [triggers](https://developers.google.com/apps-script/guides/triggers/#getting_started) limiting auth anyway? onOpen wouldn't know who is running the session. Another thing you can try to transfer the ownership of the script is go `Resources → Developers Console Project → Click link at the top` and the go to IAM&Admin and change the owner there. That's about all I can think of. – Vytautas Oct 10 '16 at 04:58
  • Are you still looking for a answer to this? If so, please add [mcve] to describe how is your script creating the spreadsheet (I think that you are using UrlFetchApp instead of the Apps Script Spreadsheet/Drive services, is this correct?) – Rubén Aug 02 '20 at 00:39

0 Answers0