4

Is it possible to access revision history data of a spreadsheet directly from Google Apps Scripts? If so, how?

I would like to do two things:

  1. Change the username logged for each revision to the actual user running the script and not the script author/owner. As I've just learned, revision history of a spreadsheet that's accessed and modified using GAS always reflects the script owner/author instead of the user running the script.

If the above is not possible, then

  1. Get direct read access to revision number and username in the history straight from GAS. From there, I'll just do a comparison table and hope for the best that I'll achieve the same effect.
Rubén
  • 34,714
  • 9
  • 70
  • 166
sabansm
  • 115
  • 1
  • 4
  • 14

2 Answers2

1

I don't believe it's possible to access the revision history with Apps Script. There is an open feature request for this ability though, and if you star it you'll receive an email when there is an update:

http://code.google.com/p/google-apps-script-issues/issues/detail?id=394

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
  • 2
    @EricKoledaa This is indeed possible in Google Apps Script. Here is a little code which obviously show how to do this. [Get the revision history of a resource using DocsList API and Apps Script](https://sites.google.com/site/appsscripttutorial/urlfetch-and-oauth/get-the-revision-history-of-a-resource-using-docslist-api) – Waqar Ahmad May 14 '12 at 17:17
  • My apologies, I should have specified that it isn't exposed in the Spreadsheet or DocsList service. – Eric Koleda May 14 '12 at 21:34
  • 1
    The issue link is not opening anymore – Kos Jun 29 '21 at 04:49
0

It's not possible to change data from the revision history.

AFAIK there is no way to get data from a spreadsheet old revision, i.e., number of sheets, sheets names, etc., but nowadays it's possible to get some metadata of some spreadsheet revisions by using the Advanced Drive Service

function logRevisionMetadata() {
  const fileId = 'put here your spreadsheet ID';
  const output = [];
  // Get revisions
  var revisions = Drive.Revisions.list(fileId, { 'maxResults': 1000 });
  console.log("Found " + revisions.items.length + " revisions");
  
 revisions.items.forEach( revision => {
      var date = new Date(revision.modifiedDate);
      output.push([Utilities.formatDate(date,'GMT-5','yyyy-MM-dd HH:mm'), revision.lastModifyingUser.displayName]);
    });
  console.log(output)
}

When I ran the above code for one of my spreadsheets I got only 24 revisions (only revisions from the current month and some of the previous month, the revisions from the previous 5 months were missing). This was already reported in the issue tracker Google Drive revision.list() does not return all stored revisions for a Google Sheets Spreadsheet

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166