0

Can a Google Apps Script determine its own resource id? If it could, then it could discover what folders it is in (parents).

If it is only in one folder, then it could use that folder as a default folder for various purposes.

If it is in multiple folders, then the resource id is insufficient to truly identify where the script was started from, so the corollary question is can a Google apps script determine the resource id of the folder it was launched from?

Seems like these would be useful additions, maybe to Class Session, if it doesn't already exist somewhere that I have missed.

Victoria
  • 497
  • 2
  • 10
  • 20

2 Answers2

0

For a Spreadsheet I found this to work:

var thisFileId = SpreadsheetApp.getActive().getId();

var thisFile = DocsList.getFileById(thisfileId);

hansvb
  • 190
  • 2
  • 9
-1

As per my knowledge, there is no option in Google Apps Script to get its own resource ID. You should file a feature request in Google Apps Script Issue tracker.

Waqar Ahmad
  • 3,716
  • 1
  • 16
  • 27
  • Thanks for the link to the issue tracker, I hadn't found that yet. – Victoria Dec 01 '12 at 04:33
  • So this `var file = DriveApp.getFileById("ME_1g1kDz8XlYx6Pq04K7aSe5QKoK0JhZ")`will not work on a GS itselve when its url is `https://script.google.com/a/macros/lagaroo.com.br/d/ME_1g1kDz8XlYx6Pq04K7aSe5QKoK0JhZ/edit?mid=ACjPJvEHKSxWGFuk9zfXT2RZ6k7d47UwTXQYzCi7YsFn6LD31COcZpXVq2-qw6dake_RrOyggYa3_9AhjEpO2hIJu6i8JD3G0JRTrd59407wALSYFEdOYMxX6vKn` ? – Jacobvdb Jun 28 '13 at 18:06