I'm using Google Apps Script to run an encryption on data in a spreadsheet. It's working fine, but that handy revision history in the spreadsheet makes it a bit of a moot point as you can simply view a version prior to the encryption.
Is there a way to delete revision histories, or to simply keep them from being created all together?
No. The Drive API for accessing revision history specifically does not delete entries on Google sheets.
Something to note revision history is only viewable by those with edit rights. View or comment only rights cannot see revision history.
One solution is to have users submit data to a very narrowly shared sheet via Google forms and set up a trigger to copy the non sensitive meta/aggregate data that you are leaving unencrypted to a more public sheet for access by untrusted users and scripts. the cell formula IMPORTRANGE() would also work it gets access permission from the person entering the formula and can therefore move data from a restricted spread sheet to a less restricted one without compromising the original sheet.
A second solution that is slightly more cumbersome, but closer to your ask, is to provide users and external scripts with access to a drive folder containing the sheet. With the ID of the folder scripts can then search for the sheet by name via the drive api, users use their eyes to find it by name. Your encryption script, once done encrypting, copies the spreadsheet using SpreadsheetApp.copy(name)which will copy all of the formulas, formatting, data, even scripts, but not the revision history. Pass copy() the same name as the original sheet, drive file names do not have to be unique. Use the drive api to move the new spreadsheet to the folder, it should inherit the sharing of the folder by default. Again with the drive API delete the original spreadsheet. Because all users and scripts were looking for a file named X in a specific folder ID everything is still exactly where they expect to find it, but the revision history is gone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With