Get ScriptID from SheetID

42 views
Skip to first unread message

Michael O'Shaughnessy

unread,
Jun 5, 2021, 9:50:20 PM6/5/21
to Google Apps Script Community
I must be missing something....

How can I get a Google Sheets bound scriptID from the sheet's ID?

I was intrigued with this post:

However I am running into some errors with a sheet that already has a script project.

I would like to have a function that I supply a Sheets ID and it returns the bound scriptID.

Any help or guidance is greatly appreciated!

Thanks,
Michael

dugBarnz

unread,
Jun 6, 2021, 6:54:07 AM6/6/21
to Google Apps Script Community
Thanks for sharing that link, Michael!

The manual way to get the App Script Id is via GAS IDE > Project Settings (on the left, gear icon, in the new IDE).

Thanks!
Doug

Alan Wells

unread,
Jun 6, 2021, 9:18:44 AM6/6/21
to Google Apps Script Community
There is no built-in, programmatic way to get the ID of the Apps Script project file bound to a Sheets file.  
An existing feature request is at the link below.  Please click the star in the upper left hand corner.

Clark Lind

unread,
Jun 6, 2021, 10:57:36 AM6/6/21
to Google Apps Script Community
As AJ said, there isn't a direct way at this time that I know of. If you have the script ID, you can get the "parent', but not vice versa. If you have edit rights to the target sheet, then you could do the hack that dugBarnz shared.. create a new tab, add the formula, maybe do .flush(), grab the cell value, then delete the tab. 

Other possibilities (thinking outside the box...).. 1)maybe try doing a urlfetch (or JS fetch outside GAS) to "https://script.google.com/home/my" and see what it returns; that would at least get you all the project names including container bound. But I don't know if you could hack beyond that with just the name.
2) outside of GAS, you might be able to do much more with Node, and something like Puppeteer to scrape  "https://script.google.com/home/my", scrape each project to grab the script IDs, then push them to a sheet via Clasp...  I dunno. 

Alan Wells

unread,
Jun 6, 2021, 2:40:47 PM6/6/21
to Google Apps Script Community
Putting a function in a Sheets cell that calls a function name in a "gs" file requires that you open the bound script file and enter the function.  So, if you are going to do that, you could just manually get the Apps Script project file ID.  
The Google Drive API won't find Apps Script files that are not visibly shown in your Google Drive.  So, the Drive API can't be used to get any information either.  And the Apps Script API won't list all Apps Script files in your account.  It will only get files by ID.  So, you can only get one Apps Script file and you need to know the file ID.

Michael O'Shaughnessy

unread,
Jun 6, 2021, 7:20:40 PM6/6/21
to google-apps-sc...@googlegroups.com
Thanks for all the info!  I am glad to see that I wasn't missing something.

@Doug  - yep, that would work but like @AllanWells said, I would have to go to each spreadsheet and add the function... if I was going to do that I might as well just look the script ID up manually.

@Clark - I will see what I can find with a UrlFetch.  Preliminary testing I can't get it to work.  It won't "log in" or use my account.  It returns just a webpage.... more testing needs to be done.

It would be great if we could somehow get the scriptID from the sheetID.  It is funny that we can go the other way...

I starred the issue with the link Allan provided.  Hopefully Google will work on a solution.

Thanks!



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/5a110dbf-749a-4cab-a987-de9c1fe9cc02n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages