Mohsen Ghasemizade
Mohsen Ghasemizade

Reputation: 1

onEdit for google docs

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('[email protected]','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.

Upvotes: 0

Views: 259

Answers (1)

Neven Subotic
Neven Subotic

Reputation: 1429

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

Upvotes: 1

Related Questions