1
votes

I have a template document with an associated container-bound script. The script does not require authentication - it simply creates a custom menu in the Google Docs UI.

The template document is owned by my GAE web app. Creating a new document via the web app uses the following process:

  1. Make a copy of the template in the web app's service account.
  2. Update the document's media_body with user-supplied content;
  3. Insert permissions to set the user as the document owner;
  4. Delete the permissions associated with the web app service account so that the document is private to the user that created it.

This process works as expected EXCEPT for the execution of the onOpen() function in the script. The script is successfully copied along with the document, and onOpen() can be run manually (using the 'Script Manager'), but it doesn't execute automatically when the document is opened. Removing step 4 solves the problem, but this makes the document 'less than private'.

Why doesn't onOpen() execute in the copied, private document?

1
This is pretty peculiar. You are saying that if a service account is collaborator on a spreadsheet, then onOpen does not run? Can you run some additional tests like adding this service account as a collaborator on docs where onOpen runs fine? - Arun Nagarajan
No, it's the other way around: onOpen() does not run after the service account is REMOVED as a collaborator. - rphv

1 Answers

0
votes

Its because the original onOpen runs with the original owner permissions. When you remove that user from the permissions, it wont be able to use those saved credentials. either dont remove it, or better yet dont change ownership just share it with the user. That will also give you more control since you will own all the system files created.