Solved

googledoc spreadsheet last modified date

Posted on 2011-03-19
5
1,715 Views
Last Modified: 2012-08-13
I am writing a script in a google doc spreadsheet that needs to check the last modified date of another google doc spreadsheet. How can I retrieve the last modified date of a google doc spreadsheet if I know its URL or key already?
0
Comment
Question by:reggieperrin
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:torvir
ID: 35173272
I tried it and got it to work with this script. The first line "var thisSheet..." and the last line are used only to be able to print the date in the present spreadsheet cell A1.
The file I am checking change date of is the file named "fileToCheckChangeDateUpon" which is a dummy file I created.

function dateOfTestfile() {
  var thisSheet = SpreadsheetApp.getActiveSheet();
  var files = DocsList.getFiles();
  var otherFileChangeDate = "Didn't find it";
  for (var n = 0; n < files.length; n++) {
    if (files[n].getName() == "fileToCheckChangeDateUpon") {
      otherFileChangeDate = files[n].getLastUpdated();
      break;
    }
  }
  thisSheet.getRange(1, 1).setValue(otherFileChangeDate);
}
0
 

Author Comment

by:reggieperrin
ID: 35184982
You rock! I tried your solution and it worked! However it is taking too long to go through all my files. How would I get it to only add jobs that start with "Job" into the files[n] array, before it starts searching through them?
0
 
LVL 5

Accepted Solution

by:
torvir earned 500 total points
ID: 35190583
If you know the file-ID you could use this syntax:
var file = DocsList.getFileById("t314159");

The script then becomes:

function dateOfTestfile() {
  var thisSheet = SpreadsheetApp.getActiveSheet();
  var file = DocsList.getFileById("t314159");
  var otherFileChangeDate = file.getLastUpdated();
  thisSheet.getRange(1, 1).setValue(otherFileChangeDate);
}
0
 
LVL 5

Expert Comment

by:torvir
ID: 35191008
The ID is the string in the URL of the document between "key=" and "&"
0
 

Author Closing Comment

by:reggieperrin
ID: 35311687
Fantastic solution! Thank you so much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Companies keep a much closer eye on costs today, so changing to new Technology – Microsoft Office 365 is the smartest move to take.
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
This Micro Tutorial will explain how to export DynamoDB tables in Amazon Web Services.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now