Two Apps Script projects bound to the same document

24 views
Skip to first unread message

Alan Wells

unread,
Mar 13, 2020, 11:29:58 AM3/13/20
to Google Apps Script Community
Until now, I'd never found a use for multiple projects being bound to the same document.  The code in separate projects bound to the same document can't access each other.  You can't call a function in a separate project.  Actually, you might be able to do that with the Apps Script API, but that would require associating a Google Cloud Platform project with the Apps Script project and enabling the Apps Script API in your Google Cloud Platform.  But, that's not how I'm using the multiple projects bound to the same document.

I am doing something similar though with two projects bound to the same Google Sheet.  I'm triggering code to run in a different project than the source  project by installing an "On Change" trigger in the project to be triggered, and using the Sheets API To set a value in the Sheet.

The code in both projects runs simultaneously, and totally independently from each other.  I'm having the calling project wait for the called project to complete before continuing on.  Both projects have access to the same Sheet, so the Sheet is being used as the way to indicate to each other what the current status is.  Eg. "Waiting" - "Done" - "Error"

I'm working on an add-on that would be able to trigger code that I give the user to run in their script project.  The reason for that is so that they can run the code that requires a restricted scope.  So, the add-on doesn't ask for permission to run a restricted scope, but can trigger user code that uses a restricted scope.

The user code is accessible to the user.  So they can look at it.  Decide if it's okay or not.  See how it works.  Determine if it's safe to run.  And the add-on will only have access to the current spreadsheet.  So, there is no chance that the add-on can set a value in another Sheet, or look at content in another Sheet.

The point of this is to be able to provide an add-on that does some of the processing, while user code does some of the processing, and the add-on doesn't need to ask for a restricted permission.  I'm using two Apps Script projects bound to the same Sheet as a way to test add-on during development.

I have no idea whether people will want to use the add-on, or trust it, or find it useful or not.  But, at the very least it's an exercise in finding out what is possible.  If anyone is interested, it's going to be an add-on that can copy the contents of one Apps Script file to another Apps Script file.  I developed it out of a need to copy development code to my production code project.  Plus it has some other stuff it does, like removing all the code comments.

Kim Nilsson

unread,
Mar 14, 2020, 9:37:42 AM3/14/20
to Google Apps Script Community
Sounds like a great way to get around the costly restricted permissions.
Will follow and provide user feedback if possible, but most likely not be able to give any coding help. :-)

Alan Wells

unread,
Mar 14, 2020, 10:53:17 AM3/14/20
to Google Apps Script Community
Thanks for replying.  I'll need to provide good instructions for the set-up, because the user will need to create a bound script with provided code, authorize it, create a GCP project, enable an API, enable an Advanced Service, and associate the GDP project with the Apps Script project.  Whether anyone will find this particular add-on worth using, I don't know, but like the idea of it, so I'm doing it.
Reply all
Reply to author
Forward
0 new messages