How to display document metadata in Google Docs

I’m working on a project where I need to extract and display various document metadata directly within a Google Docs file. I want to know if there’s a way to accomplish this using Google Apps Script or if Google Docs has any built-in functionality for this purpose.

I’ve been experimenting with different approaches but I’m not sure which method works best. Here’s what I’ve tried so far:

var docProps = PropertiesService.getDocumentProperties();
docProps.setProperty('FETCH_PERIOD', '7');

var metaData = { 
  name: 'category', 
  content: 'Marketing', 
  access: 'PUBLIC' 
};
Drive.Properties.insert(metaData, "document_id_123456");

Can anyone share their experience with displaying document properties? What’s the most effective approach for this kind of task?

Your Drive API approach works fine for custom metadata, but there’s an easier way. You can grab built-in properties like creation date, last modified, and owner straight from DocumentApp - no Drive API needed. For showing metadata in the document, I’d skip tables and use bookmarks instead. They don’t mess with your document flow. Just drop bookmarks where you want the metadata, then use replaceText() to update them. Set up triggers so everything refreshes automatically when the document changes.

I mix both approaches - works way better than picking just one. DocumentApp handles basic metadata fine, but you need Drive API for custom stuff like categories. Your code’s problem is you’re setting document properties locally while inserting drive properties separately. They don’t sync on their own. I just write a simple function that grabs both metadata types and swaps out placeholder text in the doc. Way cleaner than messing with tables or bookmarks, plus you can style however you want. Just watch the permissions when hitting Drive API properties - especially with multiple users viewing the doc.

youre mixing up document properties with drive properties. use DocumentApp.getActiveDocument().getId() first, then grab the doc metadata. i just insert a table at the top with whatever info i need - way easier than automating it all with scripts.