Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file ID in google apps scripts

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

like image 288
user3204820 Avatar asked May 25 '16 18:05

user3204820


People also ask

How do I find my Google document ID?

You get the document ID from the URL of the file. For example, if the URL of a file is https://docs.google.com/document/d/1LQ_zgy0QDy/edit , the document ID is 1LQ_zgy0QDy .

How do I find a filename in Google Drive?

Run by clicking on the right-pointing triangle in the button bar. 'Authorization required ' pop up will appear; grant authorization. A listing of the files in the specified folder, along with URLs for those files, will then appear in your My Drive as a Google Sheet named listing of folder {your-folder}

How do I view the script log in Google Apps?

A basic approach to logging in Apps Script is to use the built-in execution log. To view these logs, at the top of the editor, click Execution log. When you run a function or use the debugger, the logs stream in real time. You can use either the Logger or console logging services in the built-in execution log.


2 Answers

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

like image 112
user3204820 Avatar answered Oct 17 '22 18:10

user3204820


The id for a file/folder is also in its url. Opening a file you want the id for, your url bar says: https://docs.google.com/document/d/exampleid1234qwer5678tyui/edit

The id for that doc will be: exampleid1234qwer5678tyui

like image 4
WoahComputerScience Avatar answered Oct 17 '22 17:10

WoahComputerScience