r/GoogleAppsScript • u/itsNobir • Apr 04 '22
Resolved Pre-Authorize script to Google Workspace Domain
Hi everyone,
I have a small script on a Google Docs Template that prints the current date on the footer of the opened document via the onOpen() function.
Whenever a user generates a document via the template, it should print the current date on the footer.
The main problem is, the onOpen() triggers only to authorized scripts on Docs.
What I'm trying to achieve is, since I'm also an administrator of the Workspace, to pre-authorize the script to whoever opens the document.
Is this even doable? If not, do you know a workaround for this? I really need minimum user interaction.
Thanks in advance!
2
u/OldTinSchool Apr 04 '22
I've looked before and not found anything, commenting to follow! FWIW I think it's a noble/simple idea and I think there is also a workaround but ultimately some of these things are in place as security measures that you yourself benefit from
1
u/elcriticalTaco Apr 05 '22
Could you make a formula in the footer that's just =TODAY()? I work with sheets so I'm not as familiar with the DocumentApp but I have scripts that trigger onOpen and onEdit and neither of those require the authorization junk. Is it just doing the timestamps or is there some additional stuff happening?
Also if you figure out how to do this you will be a hero of the people lol.
Could you post the code just in case?
1
u/desirepathconsulting Apr 05 '22
You could do something like use a form to request the document be generated easily enough, and without needing any code in any files touched by users. The one form can have a single question like 'select file to generate', a drop-down of all the ones you use, and blamo.
1
u/itsNobir Apr 11 '22
Hi everyone, little update: I couldn't find a workaround for the permission.
As you suggested, I tried the TODAY() method but doesn't refresh automatically, the form idea was really good but it was rejected by my manager.
Also a problem that emerged is that you can't fire simple triggers (like onEdit()) if you don't have edit permissions on the document (some users will be read-only).
So now the workflow is:
The onOpen() creates a menu with an authorization script
The user authorizes the script
Each night around 12.00 AM the document refreshes its footer with the correct date and other data
It works fairy well like this, since the onOpen() asks for all the permissions needed to run all the functions in the script.
Thanks for the help!