Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I download previous saved revisions of a Google Apps Script?

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:

enter image description here

like image 550
daryl Avatar asked Nov 24 '15 21:11

daryl


People also ask

Where are Google script files stored?

Google Apps Script projects are now included in the docs list in Google Drive. - Your projects are now stored in Google Drive and can be shared just like any other file.

How do I view Google script logs?

Use the Apps Script execution log To view these logs, at the top of the editor, click Execution log. When you run a function or use the debugger, the logs stream in real time. You can use either the Logger or console logging services in the built-in execution log.

How do I copy a script in Google Sheets app?

Click Extensions > Apps Script. Under the script ID, click Copy. Set the script ID aside for use in a later step. Open or create a new spreadsheet where you want to add the macro.


2 Answers

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.

like image 63
Grant Timmerman Avatar answered Oct 18 '22 00:10

Grant Timmerman


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.

like image 44
Andrew Roberts Avatar answered Oct 18 '22 01:10

Andrew Roberts