I need to set the value of some pre-defined variables when user views a document inside an iframe of my application (basically, the same as Word does with DocVariables). I could note that I can do it with Google Apps Script (handling onOpen
event and replacing those variables), but my question is: how can I create this script programatically (via Java) and add it to my document (instead of user manually do it via Tools > Script editor)? Also, it is not specific to a single document, in other words, this script must be run on every document that I upload to Google Drive when user views it
Asked
Active
Viewed 76 times
0

lucasdc
- 1,032
- 2
- 20
- 42
-
Apps Script made VIA **`Tools > Script editor`** are called [Container-bound Scripts](https://developers.google.com/apps-script/guides/bound) pratically not visible in the Drive. You could try setting a external script (GAS), then control it by setting the `docID` as a variable. This would lessen the complexity of creating a new script for a new doc file. Hope this helps. – Mr.Rebot Sep 30 '17 at 19:53
-
Properties Service has the capability to save persistent data associated with a particular document, user or script. If you display a sidebar or dialog box to the user, they could save the values one time. If you are the one deciding which value is associated with which user, then you could save the values to one of the properties services. If the document is used by multiple people, then you could need to save the values to user properties, and the user would need to be signed into Google. – Alan Wells Oct 01 '17 at 01:14
-
If they are not going to be signed into a Google account, then it's pointless to use User Properties, and you'd need your own log in system. If you want to save data externally, you could access it with `UrlFetchApp.fetch(url)` or access a spreadsheet. – Alan Wells Oct 01 '17 at 01:17