11

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

1

3 Answers 3

16

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".

7
  • This saved my ass just now. Thank you!
    – atlantis
    Dec 27, 2016 at 20:29
  • In the last step, where do you see the code? @Andrew Roberts
    – user3676604
    Feb 1, 2017 at 10:16
  • Thank you very much @Andrew Roberts :)
    – user3676604
    Feb 1, 2017 at 12:42
  • I'll also add to this a bit... I forgot what functions I had in the old code so if you 1. open Resources -> Libraries 2. click the link to your old code (see my STSTrackerApp insert below You will get the functions defined and even by version. Image here -> i.stack.imgur.com/Yojla.png
    – kgingeri
    Apr 3, 2017 at 19:40
  • 5
    You can also use Logger.log(MyOldCode.anExampleFunction)
    – TheMaster
    Aug 12, 2018 at 10:58
7

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.

1
  • 2
    thank you for taking the time to address this old question :)
    – daryl
    Aug 17, 2018 at 1:55
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.