11

I am working on an app in which I need to show the date when google doc was last edited.

Snapshot Here

I am able to get last modified date through Drive api

But it is different from last edited date for cases when file's metadata (e.g. permission) has changed and content hasn't.

Is there any way to get date when google doc was last edited?

Randy L
  • 14,384
  • 14
  • 44
  • 73
Saurabh Sharma
  • 111
  • 1
  • 1
  • 3

3 Answers3

3

In Google Apps Script there is a DriveApp service that you can use. Something like this will work:

function lastUpdatedOn() {
  var FILE_ID = 'FILEID';

  return DriveApp.getFileById(FILE_ID).getLastUpdated();
}

The documentation for that is here: https://developers.google.com/apps-script/reference/drive/file#getlastupdated

Hope that helps.

Jordan Rhea
  • 1,186
  • 15
  • 34
  • I tried this, but get an Error: "You do not have permission to call DriveApp.getFileById. Required permissions: (https://www.googleapis.com/auth/drive.readonly || https://www.googleapis.com/auth/drive) (line 3). The link to the documentation does not explain to to fix this, other than saying "Scripts that use this method require authorization with one or more of the following scopes: https://www.googleapis.com/auth/drive.readonly https://www.googleapis.com/auth/drive So how do we fix that? – Rich S Nov 04 '19 at 15:59
0

Use the Update method of the Files resource, enabling the 'setModifiedDate' boolean to true. This parameter will modify the timestamp of the file edition date, whenever the file has any type of modification.

Rivero
  • 911
  • 1
  • 6
  • 10
-3

The best way to go might be to go into the Tools menu and use the "Script editor". A little bit of code makes this not so difficult. Here's one example I found that seems to work.

function onEdit(event) { var ss = event.source.getActiveSheet(); if (ss.getName() === 'Locations') { var dd = new Date(); ss.getRange(event.range.rowStart, 8).setValue(dd.toISOString()); } }

In addition to the code you will need to accept some security dialog question, and you will need to setup a "trigger" for the project. These "triggers" are how you associate the code with an event in the Google Spreadsheet.

Hope this helps.

Randy L
  • 14,384
  • 14
  • 44
  • 73
  • 4
    Apps Script don't have `onEdit event for google docs. Question is about Google Docs, however, you have answered for google sheets – RAJ Jan 01 '16 at 07:35