How to get file ID in google apps scripts

user3204820 picture user3204820 · May 25, 2016 · Viewed 14.8k times · Source

I am trying to get the ID of the doc that I am working on. Currently I am using

var files = DriveApp.getFileById('whatever the doc Id is')

and this works fine. However, I want to be able to get any document Id that this application may be running on. I don't want the user to go into the code and switch the ID depending on what document they are on. If anyone has any ideas I would love to hear them,

Thanks

Answer

user3204820 picture user3204820 · May 25, 2016

Geez I should really have more faith in my guess and check abilities.

 var files = DriveApp.getFileById(DocumentApp.getActiveDocument().getId());
 files.setDescription(des);

This works