How can I revert back to a specific revision in Apps Script? - google-apps-script

I am trying to revert to a specific revision of Google Sheet with Apps Script. I tried a couple of approach but none of them work.
Got some info about revisions here
https://developers.google.com/apps-script/advanced/drive#listing_revisions
I also tried as following different approaches
Drive.Revisions.remove("xxxxxxxxxxxxxxxxxxxx", 658);
Drive.Revisions.update(resource, "xxxxxxxxxxxxxxxxxxxxxxxx", 657);
Drive.Revisions.update(resource, "xxxxxxxxxxxxxxxxxxxxxxxx", 657);
None of the above works. Can anybody suggest what I am doing wrong or I am missing something ?

I assume here that you are talking about an older version of the script file that is attached to the spreadsheet. The script file can be thought to consist of various individual files eg main.gs, indexi.html etc, If you need to you can access older versions of each of the individual files within the script file but not the script file itself. Go.to the script file choose the individual files you want to recover and then select file -> see revision history and choose the version you would like to recover.

Related

Macros is not availible when using downloaded google sheets file

I have downloaded a google sheets file with a premade macros in it. When I went to Tools to look for the Macros tab, there was none. Anyone know how to find where it would be in this case or how to fix this error?
According to the Google Sheet Macros Documentation, there are a couple of things you cannot do with them.
When I went to Tools to look for the Macros tab, there was none.
In this case you could be facing an issue if you don't have the permissions for the file, you need edit permissions to be able to access the script (how macros are stored). if you downloaded the file and are opening it in another app, it will not work (again, as per the documentation above).
To be able to access the macros you need to be in the original Sheet, with edit permissions to be able to see/modify them. If you're accessing them externally you will need to create them from scratch.

Browse Files and folders uploaded on Google Drive

I'm writing from Italy (sorry for mistakes), my question is about GOOGLE DRIVE API and
I'm writing here because the G-Suite support wrote me to contact you, I'm not a programmer.
The big question is: how can I browse folders and files uploaded on my Google Drive Api?
I write you what apppened.
I wanted to use a backup program to save in a planned way files and folders an Google Drive.
I downloaded the program (Iperius Backup) and followed the instructions.
To understand on what I did, I paste the link of the instructions below:
http://www.iperiusbackup.net/en/backup-to-google-drive/
http://www.iperiusbackup.net/en/how-to-enable-google-drive-api-and-get-client-credentials/
I tried the software and everything worked.
So I opened Google Drive but the back-upped files weren't there.
Seen that there was something not clear, I have erased all the files on my Google Drive. I wanted to make sure that it was empty, hoping to erase also “hidden files”(...even if I thought it wouldn't have been so simple...)
To make sure that everything was erased (also “hidden files”), I tried to restore files from the backup software but unfortunately, the software worked well...the files were still there, somewhere...
This means that I have saved through the backup software files and folders on Google Drive “Api”, but I cannot manage them.
How can I have access to my space in Google Drive Api and erase all my files and folders that are still there?
Thank you in advance for the help,
best regards,
Stefano
To list all files in your drive, you can use Files: list.
This method accepts the q parameter, which is a search query
combining one or more search terms. For more information, see the
Search for Files and Team Drives guide.
You can use the Try it now or use the sample code given in a specific language you are using.
To delete/erase a file, use Files: delete.
Permanently deletes a file by ID. Skips the trash. The currently
authenticated user must own the file or be an organizer on the parent
for Team Drive files. Try it now or see an example.

Is it possible to list all scripts associated with a GDrive File though the Apps Script File Class?

I was wondering if there's a function like file.GetName(), however it would be something like file.GetScripts() to be able to find if a file has container-bound scripts.
see: https://developers.google.com/apps-script/reference/drive/file#getDescription()
I attempted something similar this past summer (summer 2014) and determined it was currently not possible, either via Apps Script nor via the Drive SDK.
In our case we were able to re-structure our project so the scripts we needed to interact with programatically were stand alone files on Drive, which we include in the relevant documents as Libraries.

How to use one code for multiple spreadsheets that can be updated, attempt to use Library

I have 200+ spreadsheet that our customers fill. I developed a script to manage the spreadsheets which is basically identical in function.
The problem is when I modify the script I need to change it in all these sheets. I tried using libraries but with no success and I hoping to hear if someone knows an answer.
The library version I include (with development on) in each spreadsheet does not show the change ensued. It will only show the results at the time of inclusion, which means that in order to make this work I have to go to each of the spreadsheets, remove the library and re-install the most recent version. The updated library only works from my owner's account. The library is of course shared by anyone who has a link.
Running a library's updated function in any of the spreadsheets produce an error:
"TypeError: Cannot find function FunctionName in object [object Object]. (line 2, file "test")"
Is there a good way to have all spreadsheets same one code that I can change whenever I wish?
You should turn on "development mode". Resources -> libraries included for each spreasheet that include the library
I have not had much success using library myself.
One solution I would suggest would be to use a standalone script. If the spreadsheets have identical features, you can run the script on all of them using a for loop.
You can get an array of files inside a folder using using getFiles()
// Logs the number of files in the 'kittens' folder
var folder = DocsList.getFolder('kittens');
var files = folder.getFiles();
Logger.log(files.length);

Backing up Gapps source

I have fallen into the trap of (accidentally) deleting all scripts from the script editor. Lost 3 weeks of work in this lesson. I (maybe) will not do that again, but it raises the question "What is a complete backup solution for Gapps source?"
I, of course, can make a copy of my script either in the editor, or within Google drive. I however question if my (very complex) User interface (built using GUIBilder) is protected. So far, I have been unable to locate the code GUI Builder throws.
Also note it is not possible to download an apps script in GDrive, so how do I get a personal copy of my work product?
=====
To clarify - I know how to copy and paste the source of a script BUT this does not capture the 200 gadget GUI that was built using GUI Builder.
As to the trap door in the editor -- I had several versions of this development -- I highlighted ONE in the left hand list and requested delete (from withing the Google script editor) file/delete -- magic -- ALL SCRIPTS DISAPPEARED. I will never touch the File/Delete menu again.
In some cases, you should be able to get your code back. (EDIT - except, it seems, any script file you delete from within the script editor, and any auto-generated code related to the GUI Builder, or Forms. -- Ouch!)
Your options depend on what you mean by deleting all scripts from the script editor.
If you only deleted the text of your script while in the editor, say by Ctrl-A + del, then you can recover it within the editor. File - See Revision History will bring up a dialog that lets you time-travel back to when your script was intact.
If you deleted the file from Google Drive, then it's in a trash folder, and can be recovered from there. You'll find the Trash folder in the Drive navigation tree.
If you deleted a script "file" from within the editor, you're out of luck until Google fixes Issue 1424: There is no possibility to recover script files/projects.
If you deleted any auto-generated code related to the GUI Builder, or Forms, you can't get them back. (Forms are not included in Restore from Revision History)
If you want to store your scripts some other place, that's a good idea - that will provide additional safety for items 1 to 3, but unfortunately not 4. You will need to copy the text from the editor into another file or online repository (e.g. Github). Get into the habit of including info about Libraries in your comments, because there is no way to back up those resource links.