0

I am trying to receive an email whenever some changes happen to my google doc. I know that there is a trigger on it for google sheets, but I don't know how to do something like that in docs. I saw in this post Google Docs Add On onEdit that it might be possible to get an update every 60s, but couldn't figure out how it would send email?

    MailApp.sendEmail('somebody@something.com','new edit')

I tried adding this code instead of callyourfunction(), bur nothing happened.

Update: Sorry I'm a beginner in Java and GAS, this is how far I got with the code:

function addTimeStamp(e){
  var row= e.range.getRow();
  var col= e.range.getColumn();
  if (col===1 && row >1 && e.source.getActiveSheet().getName()=== "Sheet1"){
      var currentDate=new Date();
      e.source.getActiveSheet().getRange(row,4).setValue(currentDate);
      if( e.source.getActiveSheet().getRange(row,3).getValue()==""){
        e.source.getActiveSheet().getRange(row,3).setValue(currentDate);
      } 
  }
}

so it would update the date in the 4th-row cell if changes happen to row 1. But What I want is to check the mentioned google docs ID in the first row and inform me of any changes that happen to that document.

1 Answers1

1

Here is the documentation for onEdit().

Depending on the number of documents you want to monitor, I would likely suggest the following alternative approach:

  1. Create a database in Google Sheets
  2. Add the Google Doc Id you want to watch
  3. Create a script (in Google Sheets) which identifies the last updated date for each Google Doc in the database. Then it should output the last updated date next to the File. Here you can also check if the last updated date is the same as the date in the database, if it is then nothing has changed. If the dates are different, then someone has updated it.

In regards to 1, create a Table with the following headers:

  1. Google Doc Id
  2. Last Updated Date

In regards to 2, add 3 Google Doc Ids, one in each row

In regards to 3, see here for how to get Sheets Data the last updated date

Neven Subotic
  • 1,399
  • 1
  • 6
  • 18
  • Thanks, Neven. Does this method show what the edit was? or it just shows the last time of update that occurred to my docs? – Mohsen Ghasemizade Feb 24 '22 at 15:54
  • It just return a Date object which indicates what the last change was. Actually looking at the difference is something you have to do by yourself, as it really difficult to note the changes. Look in the document history and you will see the changes, but that is a file per file basis. – Neven Subotic Feb 24 '22 at 17:10
  • Sorry I'm a beginner in Java and GAS, this is how far I got with the code: function addTimeStamp(e){ var row= e.range.getRow(); var col= e.range.getColumn(); if (col===1 && row >1 && e.source.getActiveSheet().getName()=== "Sheet1"){ var currentDate=new Date(); e.source.getActiveSheet().getRange(row,4).setValue(currentDate); so it would update changes on first column, but how can I point out to the context of document mentioned in that cell? – Mohsen Ghasemizade Feb 28 '22 at 16:31
  • @MohsenGhasemizade that is impossible to read as a comment. Please update your question instead. – Neven Subotic Feb 28 '22 at 19:38