I am aware of the versioning that can be done using "Manage Version". Is there a way available to get/fetch the current version of the Spreadsheet script in/using Apps script .
If you mean "Can we programmatically retrieve the script version number?", the answer is no. There is an outstanding request for this, in Issue 1369, so visit the issue tracker and star it to indicate your own interest.
Perhaps you mean "Can we programmatically retrieve the most recent source code?"
You can Import and Export Stand-alone script files through the Drive SDK. In Apps Script, this can be accomplished using UrlFetch Services.
There is no way at this time to retrieve the source of container-bound scripts, except through the Script Editor. (See Limitations.)
Reviving a dead one here but others might find this as I have still searching for a solution.
Resolution of Issue 1369 as linked in the other answer is:
Jan 22, 2018 12:09PM
Marked as fixed, reassigned to ti...#google.com.
As Federico states, with the new Apps Script API you can get script versions.
Also, with the CLI (github.com/google/clasp), you can get version info with:
clasp versions
this means we can fetch a list of versions but I still have not found a way of programmatically getting the version number and description from within a script.
Related
I have a Google Apps script file containing some functions. A certain version of this script is assigned to many projects as a library. When I do some changes in the script file I want to deploy this new version to all the projects easily without having to change the assigned script version in every project. A similar question ("Google Apps Script version deployment" change - More than one active deployment - how to update an active deployment?) has an accepted answer that doesn't seem to work: When I follow this instructions it is still the former version of the script active and the one I've edited is then listed as archived.
What do I have to do in order to deploy changes?
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
I'm trying to give the current version of a Google spreadsheet a name using Google Apps Script. In the GUI I would do File -> Version history -> Name current version but since I need to do this to multiple files, I want to achieve this using a script.
I've found the revisions reference but that's not helping much.
This question touches on a similar topic, but I've found the revisions.items.splice(-1) doesn't always list the current version but rather the latest version.
This is not possible to do at this moment. I've found a similar Feature Request. You can click on the star next to the issue number to give more priority to the request and to receive updates.
It's not exactly the same but since it's asking for API support, "update the revisions" would presumably be supported too.
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
Is there a way to use the Google Drive API's from Google Apps Script. I am aware of the DocsList Service, which allows you to look at folders and files , however what about all the other API's in Google Drive (Files,About,Changes,Children,Parents,Permissions,Revisions,Apps,Comments,Replies). For example, is there API access to add Comments to files from Google Apps Script.
Apps Script has the ability to access Google API's, but you need to explicitly enable them before they can be used.
In the code editor, choose RESOURCES, ADVANCED GOOGLE SERVICES
Click the OFF button, to turn the service ON.
Before you close the dialog box, click the link at the bottom to open up the API Manager.
Once you've completed those two steps, the Drive API is available inside of Apps Script. Type the key word Drive then type a period, and available methods will show up in a list.
Methods
get - Gets a file's metadata by ID.
insert - Insert a new file.
patch - Updates file metadata. This method supports patch semantics.
update - Updates file metadata and/or content.
copy - Creates a copy of the specified file.
delete - Permanently deletes a file by ID. Skips the trash.
list - Lists the user's files.
touch - Set the file's updated time to the current server time.
trash - Moves a file to the trash
untrash - Restores a file from the trash.
watch - Start watching for changes to a file.
emptyTrash - Permanently deletes all of the user's trashed files.
https://developers.google.com/drive/v2/reference/files#methods
(Google-Apps-Script=GAS) Drive Services added 2013.05.13 (to be announced at the 2013 Google I/O 2 days later) is apparently-exactly designed to replace the prior API(DocsList) and allow GAS to access the Google Drive SDK, though that functionality is currently not mentioned (why?) from those official docs but it is most certainly suggested by the new new API name "Drive" and is stated at as the purpose by Google's great demo video "Integrate Google Drive with Google Apps Script — Google I/O 2013" and "Drive SDK" is mentioned in by the search functions as searchFiles(String).
And Drive Services works (I'm using it; and though I could think of many improvements, haven't found any bugs of memory) including it works for useful apps (see the the video above for one of the most impressive ones I've seen) but it isn't complete (including doesn't expose the full Drive SDK) including:
it doesn't (yet?) allow one to access prior versions of content (as that vide plus (the enhancement request: Google Search for "Issue 2811: Access the document revisions using DriveApp"),
control the indexing status & method of content,
one can't get a list of a file or folder's accessors (apparently deliberately says the video; but using the prior DocsList or Library mentioned seems like it would be a workaround).
I'd have included more links to help out but I'm a new poster here so the editor's telling me "You need at least 10 reputation to post more than 2 links.".
Yes, it's possible.
Take a look at the documentation for Class File, which includes functions for obtaining and/or changing most of the attributes you've listed.
For an example of code that gets some of this info for files and folders, see this answer.
You should also have a look at this Library written by Romain Vialard, one of the GAS TC.
It provides functions that are not available directly in gas or - at least - not as simply.