Google apps domain wide apps script properties using GAS - google-apps-script

I need a domain global variable that will be set by the apps administrator of a domain and all the users apps script will read the variable and apply the settings inside their apps script.
The script is deployed as a web app. However, script property or document property cannot be used since the apps script is can be deployed across many domains. aka for a domain it should be unique property.
For example,
I am an apps admin of 'mydomain.edu', I set as
scriptProperties.setProperty('EXAMPLE_PROP', 'mydomain.edu_property');
Some other apps admin of 'somedomain.edu' sets
scriptProperties.setProperty('EXAMPLE_PROP', 'somedomain.edu_property');
Then, the setting will be in conflict. I need each domain to have unique value set to the property EXAMPLE_PROP for the same apps script.

The answer was store everything in a file. The administrator can share a readonly version of the file with all users in a given domain. I have a bunch of utilities I wrote for storing simple arrays and dictionaries in text files here.
Note: This may not be an acceptable answer see notes below.
And this link

Related

Apps Script persistent variable across all scripts?

I am trying to get a variable to work in all instances of all scripts across my user account to prevent unwanted scripts in different documents running if the variable is set. I've managed to do this by creating a file on Google Drive but it's too slow really.
I know about PropertiesService but according to the documentation this seems to only be specific to the current script or document. Is there any fast way to create a persistent variable accessible from anywhere in the google account via apps script?
There are several options
Use a project to create installable triggers instead of simple triggers,
Use a library,
Create a Workspace add-on
Create an Editor Add-on
On any of the above use the Properties Service and getScriptProperties instead of copies of the same script.

How to share a google web app outside a domain preferably without creating a marketplace addon

I'm new to apps scripting and have created a web app which is container bound to a spreadsheet.
The app provides an html form for patients to record blood pressure readings as they take them during the day. A query string on the web app url identifies the individual patient and puts their readings on a sheet, unique to them, as they submit them. The script is deployed as a web app (Publish -> Deploy as web app) and in my development account it works well.
Now I want to share the script with a few other accounts not in my domain, so that they can use it independently with their own patients, with their own web app url, with readings going onto their own spreadsheet and for me to be able to maintain the code centrally.
Researching this I see official addons are now provided through the Gsuite Marketplace. It appears my choices for 'sharing' are these:
create an officially reviewed addon and put it in the Gsuite marketplace but creating an addon for the world is not what I want to do (atm anyway!)
create a private addon for inside one domain but I want to share it with several domains
there appears to be a system for testing the script as an add-on, without publishing it and for sharing the testing but this is mentioned in the Gsuite addon docs but not mentioned in the Editor addon docs and anyway it's for testing.
share the spreadsheet in my account but then all readings end up on my spreadsheet
share the spreadsheet and code to other accounts so they can make a copy but then I can't maintain the code centrally
Can anyone suggest the best way to share this web app script so other accounts not inside my domain can use it independently but ideally so I can maintain the code centrally? Thank you.
I see two solutions here. One is to add a small amount of "user management" code to your tool. For example, include some query parameters on your base url such as email and authorization key. Set up a user-management spreadsheet with your list of users, mapping their email to a secret randomly generated authorization key, and their data spreadsheet ID.
When the script is accessed with a valid email/authorization_key combination, it then opens the relevant sheet and does its thing.
In this scenario, you would either need to have access to all the relevant spreadsheets (if the code is executing "as you"), or you would need to figure out a standardised file layout or approach that let your script locate the right files on each users drive (if the code is executing "as the user accessing the web app").
Another solution here is to use an Apps Script Library. Using a library would allow you to keep the bulk of the code in the library, while having lightweight "wrapper" code bound to each of the other users spreadsheets. This wrapper code would simply pass doGet/doPost, and any other function requests back to your library.
For example:
function doGet(e){
return YourLibrary.doGet(e);
}
function doPost(e){
return YourLibrary.doPost(e);
}
function aCallback(a,b,c){
return YourLibrary.aCallback(a,b,c);
}
In the library scenario, each sheet and script can be private to the individual users, you would just need to walk them through the initial setup/deployment, and occasionally have them bump the library version and re-publish the web-app in their copies.

How can I Find All Uses of a Google Script Library?

I have a Google Script library that is used by at least 100 other scripts (some that are bound to spreadsheets/documents, some that are not). How can I find all of these client scripts that reference my library script?
More specifically, I need to be able to add a new feature into the library that requires new permissions that I (the user) must grant. The client scripts won't run if I just add this feature to the library without granting the permissions to each of the client scripts. So ultimately, I need to give this new permission to each of the clients. And if I knew what scripts were actually using this library, I could do that manually for each one. But I need to URL's or ID's or something for each of those scripts.
Answer:
Unfortunately this is not possible to do.
More Information
It is possible to get a list of standalone Scripts from your Drive, though scripts bound to a file can not be searched for using regular searching methods.
It is possible, using the help of this Google Account page to get a list of all the Apps that have access to your account, though only files you have authorised will appear here, and apps which are not just those created by you in Apps Script will appear there (for example, other add-ons or even Android Apps bound to your account appear here).
A Partial Workaround:
Using Google Apps Script, you can list all Apps Script Projects that you own with help of the MimeType enumeration GOOGLE_APPS_SCRIPT
var scripts = DriveApp.getFilesByType(MimeType.GOOGLE_APPS_SCRIPT);
var arr =[ ];
while (scripts.hasNext()) {
var script = scripts.next();
arr.push(script)
}
Logger.log(arr);
Or even just searching for type:script in Drive, however this only returns a list of scripts that are not bound to a file.
You can then use regular Google Drive search terms to find which of these files contain, for example, a unique method name that the library uses. I am aware this isn't a perfect solution and you would still have to look for projects bound to a file using the above webpage.
Feature Request:
It appears that back in 2014 a feature request for this was made on Google's Issue Tracker, though I would suggest creating another feature request for this here as it was marked as a duplicate of another issue. You can make a feature request under the correct Apps Script component here.
References:
Google Apps Script - Enum MimeType
Google Drive Search Query Terms
Apps with access to your account
Google's Issue Tracker
Feature Request: Listing and searching for container bound scripts
Create an Apps Script Feature Request

Can Google Apps Scripts be flexible enough to handle multiple sheets?

Is it possible with one Google Apps Script published as a Web Application to be flexible enough to connect to different spreadsheets depending on the person or webmaster using the Application?
I saw when working with one of my scripts there are ‘script properties’ and then ‘user properties’ tabs under ‘Project properties’.
I tried to add a property but couldn't get it to Stick
So then I found Google Apps Script ‘Class Properties’ area.
When I think of how these two properties might work, I think of Google Gadgets. A user can add a gadget to her Google Site but can then change or configure the Gadget in the properties area of that gadget
Is this type of functionality possible?
You can configure settings that will allow one script to access the files of the user of the Apps Script. The user needs to log in with their Google account.
You can publish the Apps Script script to run as ANYONE, and Execute the app as: User Accessing the Web App. Which requires the user to log in with their Google Account, and will allow the script to access the users files.
The Properties Service is for storage. It doesn't set or grant permissions. A break down comparison of the different types of Properties is shown at:
Comparison of Property Stores
For the question, 'Can Google Script me modified to run differently depending on who's running it', yes.
For example, you could use the function 'getActiveUser()', and dependent on who the user was, you could set a variable such as 'thisUsersSheet == usersSpreadsheet key', among many other ways to do this.
Whether or not it would be possible to have it replaced site gadgets, that's much more dependent on what you're trying to achieve specifically.
Note: You mention 'Script properties' and 'User Properties' in your question. Stay away from these, they are deprecated.

Adword Script in Google App Scripts

I am not able to find Adword API support in Google App Script,I can write adword script from adword account but currently i'm handling multiple account(almost 25) what i have to do is go inside individual account and copy my script in that account and adword script have limitation of maximum 15 script can be run by one user at a time, i want to create database of all account at one place that is possible through adword api in java and other programming languages,but i'm quite familiar with Google App script i want to use Adword API in App Script,how can i use UrlFetch() class of Google App Script to use adword api, so that just by replacing client Id of adword account i can get all data at one place(i have access to all account so no need to change username and password).
Thanks in advance for any help and information!
If I understand correctly, the main problem is that you want to to basicaly make a "code library?" So reuse the same bits of code between accounts?
One option is to use the Eval function, as detailed in tip 3 of this article: http://www.ppchero.com/tricks-for-running-adwords-scripts-in-multiple-accounts/. A second example of using this same method is here: http://www.freeadwordsscripts.com/2013/10/use-gdrive-to-load-single-adwords.html
You would then upload this into Google Drive, or point this to the location of the Google Script.
Another option, as detailed in the PPC Hero Article, is to use Google Sheets to pass the variables you need from one script to another. Basically, the SpreadsheetApp function works within all AdWords scripts, so you can use this to pass data along from external sources.
There are some example scripts regarding Adwords associated with these posts:
http://searchengineland.com/four-ways-you-can-benefit-by-using-adwords-scripts-145530
http://googleappsdeveloper.blogspot.co.uk/2012/12/adwords-analysis-in-google-apps-script.html?m=1