I got the below script for automatic "last edited" timestamp in the footer of a Google Document.

function lastEdited() {
  var doc = DocumentApp.getActiveDocument();
  var id = doc.getId();
  var file = Drive.Files.get(id);
  var footerSection = (doc.getFooter())?doc.getFooter():doc.addFooter();
  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);

But there is below mentioned error in this

SyntaxError: Unexpected token ':' (line 4, file "Code.gs")

Can anyone help me in this?

  • Welcome to Web Applications What is the line 4? Have you already enable the Google Drive Advanced Service? What runtime are you using?
    – Rubén
    Sep 5 '20 at 20:18

You need to enable the Drive API in the advanced Google service first:

enter image description here

From the script editor go to Resources > Advanced Google service and turn the Drive API on. Onces you've done that, you need to press the bug button to authenticate the script again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.