Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Is there a way to insert an automatic "last edited" timestamp in the footer of a Google Document?
I would like to make sure that time stamp is on the document when I print. I figure out how to enter a "today" time stamp but need a script to pull "last edited" and, if possible, the user that last edited.
Yes, there is. Use file.lastModifyingUserName and file.modifiedDate.
Example:
function lastEdited() {
var doc = DocumentApp.getActiveDocument();
var id = doc.getId();
var file = Drive.Files.get(id);
var footerSection = (doc.getFooter())?doc.getFooter():doc.addFooter();
footerSection.clear();
var userName = file.lastModifyingUserName;
var date = file.modifiedDate;
var text = '[Last edited by ' + userName + ' on ' + Utilities.formatDate(new Date(date), 'GMT+5', 'YYYY/MM/dd hh:mm') + ']';
var p = footerSection.insertParagraph(0,text);
p.setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}
This was a good start, but it didn't require all the functionality that was needed for me. The correct timezone, the correct place in the document for it to be inserted. The ability to add gif images and updating live text and time since last edit.
This script is a Google Apps Script written in JavaScript that is designed to work with Google Docs. Its primary purpose is to perform various functions related to tracking and displaying information about related the time since the last edit of a Google Doc. More over, the script interacts with the document, access user properties, and make modifications to the document's content based on the time elapsed since the last edit.
I hope someone finds this useful and learns from it. Maybe they will help make this code better. If you like, I would be happy to hear your thoughts.
Welcome to Web Applications SE. The context of this answer is not clear. What do you mean by "This was a good start"? Please bear in mind that this is not a discussion forum. When posting an answer, please ensure that it answers the question and is self-contained. If it is relevant to mention something said in a previous answer or refer to it, please refer to it by date, author, or other non-ambiguous means. The answer order is not always reliable and might vary from one user to another due to the answer sort option. Ref. How to Answer.