I have several dozen Google Sheets that I manage for my company that all use the same Apps Scripts library and I am trying to find the easiest way to be able to update the library and have the changes propagated to the Google Sheets. I understand the use Development mode so that the Google Sheets using the library have the most up-to-date code however that requires giving edit privileges of the Apps Scripts project to the Google Sheets users.
The alternative is to turn Development Mode off so that users would only require read privileges however, to then update the code used by the Google Sheets, I would need to save a new version of the Apps Scripts library and then manually update every Google Sheet with the new library version.
Is there anyway to update the library version used by a Google Sheet using one of the Google APIs or some other way that could be done programmatically?
Sorry for answering after 1 year,
If i understand, you have a Script Project which is a library for several users project and your problem is to deploy a livrary version in every client project.
As Alan Wells says, you just have to replace the manifest of each client project.
Your manifest is a appsscript.json file. (you could show/hide the manifest file in a project)
Manifest file syntax :
{
"timeZone": "XXX",
"dependencies": {
**** SOME dependencies you need for the client****
,
"libraries": [{
"userSymbol": "MAIN_SCRIPT_NAME",
"libraryId": "MAIN_SCRIPT_ID",
"version": "MAIN_SCRIPT_VERSION"
}]
},
"exceptionLogging": "STACKDRIVER"
}
You could use CLASP to manage your script easily.
In your example, in clasp, you create a master folder for your project and a subfolder for every Clients Script. You need to sync every subfolder to his GoogleAppsScript.
The initialisation could be long and boring, but with a little shell you be able to push the manifest to every client script with on click/script..
You just have to modify the manifest into your Master Folder and run a script like :
for x in `ls -d SubFolder*`; do (cp appsscript.json $x ; cd $x; clasp push -f >/dev/null ; cd ..; echo "Update done on "$x) ; done
Now you can update the manifest for every client, Library version is available, but the dependencies too... (if you need start some new, or end others)
Related
Is there a way to restore previous Google Apps Script Editor Versions?
I accidentally deleted a big portion of my code in the Google Script Editor. In the new editor, I do not see a way to restore versions.
In the old editor, I can go to File > See version history (please see image).
Unfortunately, this only goes back a few hours.
Is there a way to retrieve a version from yesterday?
TIA
You can try reverting to the legacy editor to access your script revision by clicking on the "Use legacy editor" button on the top right of the Apps Script window.
Even if you weren't already using clasp, when you created those versions, you can still use it now to retrieve the code for them. However, this only works if you created an explicit version of the code, under deployments, even if you didn't actually deploy them.
First install NPM, then:
npm i #google/clasp -g # install clasp
clasp login # login to your Google account
mkdir some_folder
cd some_folder
clasp clone <ScriptId> # replace <ScriptID> with your script id
clasp pull --versionNumber X # replace X with version number you want
We are building an addon using Google App Script and want to publish it to Google Workspace MarketPlace. We are managed to publish versioned deployment using the Manage Deployment feature of App Script.
We are looking to configure CI/CD for App Script addon (whenever changes committed to a git branch, a new deployment id should be created and respective code should be published on Google Workspace MarketPlace).
We didn't find any workaround to configure CI/CD for App Script. Our preference is Azure for CI/CD.
You can use a combination of the
Apps Script API
Where you can manage deployments and versions.
Workspace Marketplace API
Where you can control your app listing.
You may not be able to do absolutely everything but that will be your best place to start.
I am not familiar with Azure but you can look into git actions to run some API request to the above APIs whenever you make a commit to the main branch.
I currently use a Google App Scripts on Google Sheets for my budgeting spreadsheet. Essentially, the way I have it set up is:
Buy item
Input expense onto Google form (which feeds into a spreadsheet)
Use Apps scripts to convert timestamp into yyyy-MM-dd
I've been using this process for 4 years but all of a sudden, today it stopped working by giving me this error below.
Error 401: deleted_client The OAuth client was deleted
Here's my app script:
Here's my trigger:
At some point your Apps Script project's attached Google Cloud Platform (GCP) project (which manages the Oauth client) was likely deleted. You could confirm this by going to the Apps Script project editor, click the gear on the left for Project Settings, then click the Project Number link in the Google Cloud Platform (GCP) Project section. If it loads the GCP console (using the correct Google account) but gives you an error instead of bringing you to the project, then it probably doesn't exist anymore.
First, check if it's been deleted within the past 30 days and could be recovered:
In the GCP console, go to the Manage resources page (project picker → three dots button → select your organization → Manage resources).
Below the list of organizations, folders, and projects, click Resources pending deletion.
If you see the project there, check the box then click Restore. In the dialog that appears, confirm that you want to restore the project.
Go back to the Apps Script project editor and run one of your functions, and it should allow you to authorize the project again instead of giving you the 401 error.
If the project does not appear in the Resources pending deletion list because it'd been deleted over 30 days ago:
Copy all of your Apps Script projects' files to your local machine. If there are many files, consider using the clasp CLI tool, which would allow you to clone the entire project locally with one clasp pull command.
[IMPORTANT] Confirm that all of the files have been stored locally (and backed up, if desired), because the Apps Script project will be deleted permanently.
Make note of any services which are enabled in the Services section of the Apps Script project editor sidebar.
Delete the Apps Script project by going to the Apps Script project's Overview page, then click the trash can labeled Delete project forever.
In your Google Sheets doc, go to Extensions → Apps Script again and it will create a new Apps Script project (with attached GCP project).
Save the default Code.gs file
Re-create the projects' files. If you'd used clasp pull in the first step, then you can use clasp push to push the files from your local machine back to the project. In this case, go to the Apps Script project's Project Settings page and copy the Script ID. Then update the scriptId in the local .clasp.json file, save it, then clasp push.
If there were Services enabled in the previous project, enable them again in the Services section of the editor sidebar.
Run one of your functions and it should allow you to authorize the project again instead of giving you the 401 error.
I wanted to find some library which is similar to pandas in Python and use it in my google script. I've found danfo-js https://github.com/opensource9ja/danfojs
And using this guide https://blog.gsmart.in/es6-and-npm-modules-in-google-apps-script/ did install it in google cloud shell
so, actually here what I did:
opened my google cloud shell
installed clasp tools
clasp login
npm install danfojs-node
created new google script using: clasp create --type standalone --title "first GAS App"
So now, I have this empty script and just wanted to check does it see the danfo-js library.
To check this I have filled it out with the following code:
function myFunction() {
const dfd = require("danfojs-node")
const tf = require("#tensorflow/tfjs-node")
let data = tf.tensor2d([[20,30,40], [23,90, 28]])
let df = new dfd.DataFrame(data)
let tf_tensor = df.tensor
console.log(tf_tensor);
tf_tensor.print()
}
After I run this script I am getting the following error message:
[20-10-18 06:17:53:783 PDT] ReferenceError: require is not defined
at myFunction(Code:2:15)
It links on the following line:
const dfd = require("danfojs-node")
Looks like the compiler doesn't know what is "danfojs-node" but I don't understand what steps did I miss.
I did install danfojs-node, using the following command in google cloud shell:
npm install danfojs-node
and using the same terminal window I created this script.. maybe I should set some link inside the script to connect to this library, but I don't know where should I do it.
Apps Script is not Node.js.
You cannot install external modules and libraries the same way you would when creating a node.js application. The supported way of using external libraries in Apps Script is by installing them through the project's resources.
So essentially, this can be done by going to the project's Resources > Libraries....
You have to check if the library you plan on using is supported by Apps Script and if so, include it using the step above.
Reference
Apps Script Libraries.
Looking for help/directions on the following issue:
Apps script Web App losing permissions frequently.
A detailed explanation of the deployment:
I have a GAS Web App that has been published as a Web App and it is being "Executed as Me".
I have also created a version, and the script is then published on this specific version. Script also has a few time-driven triggers which are also set up on a specific published version.
According to Google Apps Script Documentation,
above are the best practices to be used for the deployment of an Apps Script project as Web App.
But recently, this GAS/Web app is losing permissions automatically even though there is no change in the script. So eventually, script triggers start throwing an error: "Authorization is required to perform that action".
Is there anything I am missing?
FYI, below are the permissions required for my script:
"oauthScopes": ["https://www.googleapis.com/auth/spreadsheets.readonly",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/gmail.modify",
"https://mail.google.com/",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/forms",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/drive"],