I created a web app for my google sheet script.
I deployed it with version 1 and and it works
Now I want to make on going changes and deploy my changes,
Do I need to increase the version for each change I deploy? or can I update on current version?
Also, is there a way to get the current version programmaticaly?
For your situation, I would like to introduce because I had a workaround that I also use.
For question 1 :
In generally, when the script of Web Apps was updated, the project version is required to be increased and Web Apps is redeployed with the new version.
But if you want to deploy Web Apps without increasing the version, as a workaround, you can achieve it by using a library. The flow of for this workaround is as follows.
Create 2 projects.
One is the project that Web Apps is deployed.
It supposes that this is the project that you are using now.
Another project is used as a library. Please create this as a standalone project.
Please create a version.
On script editor
File -> Manage versions...
After input description, please click "Save new version".
Please copy this script ID. This is used for installing the library.
For the project that Web Apps is deployed.
Please install the library project as a library.
On script editor
Resources -> Libraries...
For "Add a library", please input the file ID of library project.
Turn on "Development mode".
Set the version to the saved version.
In this sample, please set "Identifier" to "lib".
Please copy and paste the following function. In this project, the script is only this. And please save the project after copy and paste it.
function doGet(e) {return lib.main(e)}
Please deploy Web Apps as a new version.
After this setting, you are not required to modify this project.
For the project which is used as a library.
Please copy and paste the following function.
function main(e) {return yourfunction(e)}
yourfunction(e) is the function in the project that you are using.
In this workaround, when you want to modify the script, please modify the library project. By this, when the library is updated, the project which deployed Web Apps is automatically updated because "Development mode" is turned on when the library is installed. This update is also reflected to Web Apps. So the script of Web Apps can be updated without increasing the version.
As a sample, the scripts for both project after making the settings described above are as follows:
For the project that Web Apps is deployed.
function doGet(e) {
return lib.main(e);
}
For the project which is used as a library.
function main(e) {
return yourfunction(e);
}
function yourfunction(e) {
do something: The script which is run when users accessed to Web Apps.
return something
}
For question 2 :
In order to retrieve the current version of the project, you can use Apps Script API. This is also answered by tehhowch. In a recent update, users got to be able to retrieve and create the project versions. By using this, you can achieve this. The required scope is https://www.googleapis.com/auth/script.projects or https://www.googleapis.com/auth/script.projects.readonly.
The endpoint for retrieving the version list is as follows.
GET https://script.googleapis.com/v1/projects/### scriptId ###/versions
If you want to create the new version using script, you can use the following endpont.
POST https://script.googleapis.com/v1/projects/### scriptId ###/versions
Request body is
{
"versionNumber": 3,
"description": "sample description"
}
References :
Web Apps
Libraries
Google Apps Script API
Method: projects.versions.list
If this was not useful for you, I'm sorry.
When creating a web app for apps script, two links are given:
The one ending exec will only load the specified published version of the code.
The one ending dev will load the latest saved code (allowing for testing of code prior to making a new version).
Programmatic control of the deployed version is available via the Apps Script API, and to a Dev environment via clasp.
Getting versions
Creating versions
You need to increase the version for each change, unless you use the "dev" version of the app when it will always display the latest version. This will only be visible when you are logged into your account though.
It's much easier than everyone makes it sound
Go to Deploy:
Click "Manage deployments"
Under Configuration click the edit pencil
Under "Version" click "New Version"
Click "Deploy" it will auto increment the version for you
Related
When creating a trigger programmatically, i.e. through ScriptApp.newTrigger(), does it always point to the "head" deployment, or the most recent published (versioned) deployment? (See documentation on deployment types here.)
For context, I'm distributing a script in a multi-user environment which relies on triggers to run every few minutes. I'm trying to ensure that changes made in development (i.e. before publishing those changes) are not picked up immediately by all the clients of the script, as this effectively means any code updates in dev are instantly live for all users.
If triggers can only point to head deployments, what are best practices for pointing them at code which can be safely updated in dev (head version)?
You want to know that when a trigger is installed by ScriptApp.newTrigger(), which version of script is used.
You want to know the method for installing a trigger by selecting version of script.
I understand your question like above. If my understanding is correct, how about this answer? Please think of this as one of several answers.
Answer for Q1:
When a trigger is installed by ScriptApp.newTrigger(), although the value of "Deployment" is not shown in "Current project's triggers", the latest script is run by the installed trigger. This situation is independent of the version of script. The current latest script is used.
If the trigger is manually installed, you can select the deployment version at "Choose which deployment should run".
Unfortunately, in the current stage, this cannot be achieved by the script yet. I think that this might be achieved by the future update.
Answer for Q2:
In order to install a trigger by selecting version of script, as a workaround, I would like to propose to use a library. The flow of this workaround is as follows. This is a sample flow.
Create 2 standalone projects.
One is used as a library.
Another is used as the project to use the library.
In the project to use the library, for example, function myFunction() {lib.myFunction()} is put. This script runs the function of the library.
Install the library to this project.
You can select the script, that you want to make users run, by selecting the version of library.
Trigger is installed to this project.
The project of the library is the project for developing. It manages the version of developing script by "Manage version" of the script editor.
When the trigger is installed, it runs ScriptApp.newTrigger("myFunction") in the project to use the library. At this time, when the trigger is run, the selected version of library is used. By this, the latest script of library is not used. Users can use the stable script of the version you selected.
Note:
You can also see the version of library at Manifests file (appsscript.json). This file can be modified by the script. By this, you can also modify the version of script using by the trigger by the script.
References:
Libraries
Manifests
If I misunderstand your question, I'm sorry.
Yes, it always point to the "head" as versioned deployments are only available for Gmail Add-ons.
The above is based on that the only the guide to publish a Gmail add-on includes as step the creation of a versioned deployment -> https://developers.google.com/gmail/add-ons/how-tos/publish#step_1_create_a_versioned_deployment
I am still attempting to recover from somehow 'loosing' a Google Apps Script when I created a copy of the script to fork the code to another project... My thought was to attempt to download older revisions of the Google Apps Script via the drive API, but this page indicates that perhaps it is not possible.
Actions such as versioning, publishing or executing the script are not available through the API.
So I attempted it anyway and alas this error occurs...
<HttpError 400 when requesting
https://www.googleapis.com/drive/v2/files/..snipped../revisions?alt=json
returned "File does not support revisions">
So is there no mechanism to download previous versions or "Revisions" of Google Apps Script? What I would love is to get access to 'Revision 1' shown here within the script.google.com interface:
This is a bit manual but:
Create another script project
Include your original script as a library in your new script and select v1
In the new script add some code that uses your "library"
Use the script editor debugger to step into the library and you should see the code from the correct version
For example if your library is called something like "MyOldCode", include some code like this in your new script:
function getOldCode() {
var a = MyOldCode.anExampleFunction()
}
Put a breakpoint below the "var a" line, run getOldCode() with the debugger and then step into anExampleFunction(). This will open up one file of your old code allowing you to copy and paste it elsewhere.
You can then piece together v1.
Edit 2019-04-11: There is also Romain's function for accessing old versions.
Edit 2022-05-05: With V8 and the new editor I can no longer find a way to step into a library. Rhino gives a server error, and V8 ignores the "step in".
FYI, the Apps Script API can get project files from a previous version number:
https://developers.google.com/apps-script/api/reference/rest/v1/projects/getContent
If you'd like to see this in the Apps Script CLI, clasp, like clasp pull 3, I'm sure I could add this feature.
https://github.com/google/clasp/
Just file a new issue.
Grant is the right answer. Clasp is the way. I just wanted to update the command for the current state of clasp which is
clasp pull --versionNumber 12
I am working on an add-on for the new Google spreadsheets but I wonder how versions are handled? In the old script gallery, there were versions. Are they working the same in add-ons after the add-on is published?
Also I see an auto generated Help submenu item. How do I generate content for it?
Thanks.
Thanks to #Steve Lieberman answer I see now how to choose on publish and update later the version of the add-on. But in the documentation I can't find an explanation of what will be the effect of updating to a new version on already used copies of the add-on. Will they be automatically updated? Will they receive in some form a notification of the new version?
Thanks.
When you publish your add-on [1], there's an option to select the version of the script that will be used.
Note there's also a version of the Chrome Web Store entry, this can differ from the version of the script.
The source code that is executed will be based on the version of the script that is published to the Chrome Web Store.
[1] https://developers.google.com/apps-script/add-ons/publish#publish_your_add-on
First create a new deployment/version of the script in the script editor.
Then update the script version in the Project's Google Workspace Marketplace SDK page, App Configuration tab (scroll down), then Save it.
Note that the update will take effect immediately when Saved, including for documents that are currently open in a browser.
Debugging: I don't think it's possible to have multiple deployments/versions of a Published Add-On active at the same. You have to do your debugging of the HEAD version in the Add-On's Host document, or in a document that does not have the Add-On installed (you can add the HEAD deployment of the Project as a script library in that case).
I am using Google Apps Script and was wondering if I could use any sort of editor outside of the one Google provides. (I purchased Sublime Text and would like to use that.)
The one Google provides is disgusting, with tiny text even though I have a giant screen and syntax colors that I find a bit difficult to distinguish on a white background with small text, and I don't have the beauties of Sublime like tons of custom keyboard shortcuts, all of my packages, etc.
As of today (May 2018), every scripts that you add on Google App Scripts (including scripts on Google Drive like spreadsheets) will get accessible through https://script.google.com and will have a specific id that you can get through the url by opening it.
By using clasp which handle a project (like git), you can do:
clasp clone {id}
to have your script in a local folder.
Then, after editing your file with your favorite text editor, upload it back with :
clasp push
Google has dropped support for Apps Script inside Eclipse but you can set up a local development environment inside VS Code using the Apps Script Starter kit and CLASP.
Here's a video tutorial to help you get started.
The eclipse plug-in is migrated now. You should install many
files. lastly it couldn't import my google script files.
nod-google-apps-script is depercated.
gdrive can't handle google scripts beyond exporting the project in single json file. issue issue
sublime-editor-plug-in has n't worked for me (I read the whole documents & issues)
The only working solution for me (ubuntu xenial) is clasp.
According to doc it can :
Develop Locally: clasp allows you to develop your Apps Script projects locally. That means you can check-in your code into source control, collaborate with other developers, and use your favorite tools to develop Apps Script.
Manage Deployment Versions: Create, update, and view your multiple deployments of your project.
Structure Code: clasp automatically converts your flat project on script.google.com into folders. For example:
On script.google.com:
tests/slides.gs
tests/sheets.gs
locally:
tests/
slides.js
sheets.js
N.B:. The fature of 'Manage Deployment Versions' isn't supported by eclipse plug in.
It give the following commands:
clasp login [--no-localhost]
clasp logout
clasp create [scriptTitle] [scriptParentId]
clasp clone <scriptId>
clasp pull
clasp push
clasp open
clasp deployments
clasp deploy [version] [description]
clasp redeploy <deploymentId> <version> <description>
clasp version [description]
clasp versions
By using it; you can use your favorite script editor; then push the changes.
Edit
GAS Editor Autocomplete
Thanks to #tehhowch comment.
Auto complete of google objects is almost exclusive for online GAS editor, If you use any external editor , you will only get auto complete for the functions & variables of your own script (I am not sure about eclipse).
But online editor provides autocomplete which reveals the global objects as well as methods and enums that are valid in the script's current context.
To show autocomplete suggestions, select the menu item Edit > Content assist or press Ctrl+Space. Autocomplete suggestions also appear automatically whenever you type a period after a global object, enum, or method call that returns an Apps Script class. For example:
If you click on a blank line in the script editor and activate autocomplete, you will see a list of the global objects.
If you type the full name of a global object or select one from autocomplete, then type . (a period), you will see all methods and enums for that class.
If you type a few characters and activate autocomplete, you will see all valid suggestions that begin with those characters.
You can use node-google-apps-script to edit scripts locally (described in this blog post from the google apps developer blog on 2015-12-17). This way you can use a more comfortable editor, version control and build scripts.
Caveats:
Like the eclipse plugin, node-google-apps-script requires that your add-on is a standalone script.
Debugging still requires google's script editor. With some additional setup you could run functions via the Execution API
It would be awesome if there was a Sublime Text plugin for code completion of google library methods, but I haven't found one (I don't think their default browser editor even offers this, though)
This is an answer for basic/beginner users of Intellij that are looking for code completion when writing Google App Scripts apps. Most of the answers above were helpful for getting me going, especially with Clasp. But none of them actually got Intellij to do the code complete. But this does:
Select File, Settings, Languages & Frameworks, JavaScript, Libraries.
Then on the right select Download, the scroll down to 'google-app-scripts'. (Lots of scrolling) Download and install and you're done. Almost so easy that it really shouldn't have been so hard to find.
Another option to contemplate: using "AppsScript Color" Google Chrome plugin and GAS editor shortcuts.
Here you have a list of most useful shortcuts:
https://opensourceseo.org/useful-tips-for-using-the-google-apps-script-editor/
You can just install a Google Drive command line client (e.g. https://github.com/prasmussen/gdrive) and edit .gs scripts directly.
There's also a way to edit Google Apps Scripts in Eclipse, which may be interesting. https://developers.google.com/eclipse/docs/apps_script
I use Google App in my company, and I often have a prob when I update my script.
When I Update my script , my Webpage on Google sites is not updated , and for long time.
I must create a new script when I update my script.
Can I resolve this problem ?
regards
There are two ways to publish your code:
A) Either by deploying a new version, which is done as follows:
File -> Manage Versions
Add a new version -> Close dialog
Publish -> Deploy as web app
Select the version added -> Update
B) Or by always using your latest code
Publish -> Deploy as web app
Under the web app URL, click on the latest code button.
This way, any change done and saved will automatically be updated upon a refresh
Follow the instructions in the documentation. You need to first save a new version in the versions dialog. Then you need to re-publish it using the new version number.