Check for New Documents


Purpose: 

Goes through your documents and check to see if it has been updated in the last 2 days.  If such documents exist an email is sent to the user with a list of the names of the documents. Note this works for documents only not spreadsheets or presentations.

Installation:

1. Original Changes in Documents can be found HERE. Make a copy.
 

Use Details:


Open the spreadsheet and open the script editor:



Change the username to your email address and save the script:
var userName = "pausman@bcdschool.org";


var userName = "pausman@bcdschool.org";


Setup a trigger so the the script runs nightly:

Create a new trigger.





Under resources select Current script's triggers.

Change to Time-driven
Change to Day Timer
Change to 5am to 6am
Save the trigger.









Run the script once to authorize:



Code:


function notifyMe() {
  var userName = "pausman@bcdschool.org";
  var myDocs = DocsList.getFilesByType("document");
  j = 0;
  var updatedFiles =new Array();
  var urlBase = "https://docs.google.com/Doc?docid=";
  var today = new Date();
  var emailtext = " Files that were changed in the last 2 days: " + "\r\n";
  for (i = 0; i < myDocs.length; i++) {
    lastUp = myDocs[i].getLastUpdated();
    if (dateDiff("d",lastUp,today) < 2) {
      updatedFiles[j] = myDocs[i].getName();
      j = j + 1
     }
  }
 
   for (i =0; i< updatedFiles.length;i++) {
      emailtext = emailtext + updatedFiles[i] + "\r\n"
   }
  if (updatedFiles.length > 0){
   MailApp.sendEmail(userName, "Updated Documents", emailtext);             
  }
  } 

function dateDiff(datepart, fromdate, todate)// datepart: 'w', 'd', 'h', 'n', 's'
{
    datepart = datepart.toLowerCase();
    var diff = todate - fromdate;
    var divideBy = {
          w:604800000 //1000*60*60*24*7
        , d:86400000 // 1000*60*60*24
        , h:3600000 // 1000*60*60
        , n:60000 // 1000*60
        , s:1000
    };
    return Math.floor(diff/divideBy[datepart]);
}

Revision History

Version 1.0 April 2012 Pat Ausman pausman@bcdschool.org.