0
votes

If I publish a doGet(e) function from a GAS bound to a spreadsheet to create a web app, I can get a handle to the containing spreadsheet by using SpreadsheetApp.getActiveSpreadsheet().

If I give my script all permissions to act as myself and give "everyone" permission to run it, after I close the spreadsheet, a call to SpreadsheetApp.getActiveSpreadsheet() returns null. I am forced to use openById(Id) or openByUrl(Url) with the correct parameter to get the handle.

I assumed there'd been a way to get the container's spreadsheet id from a bound script, otherwise if I wanted to copy a script from a spreadsheet to a new document, I'd have to update the url or the id in the script.

1

1 Answers

1
votes

"I assumed there'd been a way to get the container's spreadsheet id from a bound script, otherwise if I wanted to copy a script from a spreadsheet to a new document, I'd have to update the url or the id in the script."

This is actually a bad assumption. When a standalone webapp is running there is no "active spreadsheet", the only way to access it is to open the spreadsheet by its ID or url.

This implies indeed that the script has to be updated with the new ID is you want to make it run along with a new sheet data set.