0

Is it possible to get the Data which has been added/updated after specific date using google app script? if so, how?

My requirement is I want to fetch all the changes in a google doc which has been made after a particular date.

Saurabh Garg
  • 199
  • 7
  • 22

1 Answers1

1

I had some trouble with fileSize on the example so I left it out and this example includes the requirement of only including files after a given date/time. Mostly it's a direct copy of the other example. I also added a link to the revision and it gives you a snap shot of the revision.

This is the code along with a test function.

function testGRH()
{
  getRevisionHistory(new Date('June 11, 2017 8:27:03 PM MDT'));
}

function getRevisionHistory(after)
{
  var s='';
  var br='<br />';
  var doc=DocumentApp.getActiveDocument();
  var id=doc.getId();
  var revisions=Drive.Revisions.list(id);
  if (revisions.items && revisions.items.length > 0) 
  {
    for (var i = 0; i < revisions.items.length; i++) 
    {
      var revision = revisions.items[i];
      var date = new Date(revision.modifiedDate); 
      if(date>after)
      {
        s+=br + Utilities.formatString('ID: %s, Date: %s <a href="%s" target="_blank">Link</a>', revision.id, date.toLocaleString(), revision.selfLink);
        Logger.log('ID: %s, Date: %s', revision.id, date.toLocaleString());
      }
    }
  } 
  else 
  {
    Logger.log('No revisions found.');
    s+=br + 'No revisions found.';
  }
  if(s)
  {
    DocumentApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(s), 'Document History for ' + doc.getName() + ' after ' + after);
  }
}

And this is my dialogs output. Checkout the link.

enter image description here

You will have to enable Drive API in the API Console.

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • Google Documents, Spreadsheets etc. doesn't consumen storage quota so it's very likely that they haven't a size property. – Rubén Jan 16 '18 at 19:43