What is the scope/persistence of an object activated by a triggered function in Google Spreadsheet API?

51 Views Asked by At

Google Spreadsheet API has various methods for setting the active Spreadsheet, Sheet, Range, column, and so forth, programmatically. These methods can be used from triggered scripts that run when the UI isn't open. However, I don't see any documentation explaining how long this activation persists.

Experience and intuition suggests that when, say, a spreadsheet is activated programmatically, it is "active" in the global scope, and will stay active until the original function call ends. However, I am afraid I will be surprised by some edge case if this is not exactly right.

For example, if I have a bound script that is triggered to run on Friday, and it calls another bound script which activates a spreadsheet, it seems that the spreadsheet remains active after that second script closes, and another script call can still "getActiveSpreadsheet". However, if the triggered script terminates, and another script is triggered 5 minutes later, you would have to activate it by ID again.

Is there any documentation, or is my understanding complete?

As an example, consider a case where one Google Service's API is triggered by the result of a change caused by a triggered function in a separate service.

1

There are 1 best solutions below

9
Mr.Rebot On

getActiveSpreadsheet()

Gets the active sheet in a spreadsheet. The active sheet in a spreadsheet is the sheet that is being displayed in the spreadsheet UI.

It is not discussed in the document on how long the document is active or could remain active. But it is written as long as it is being displayed in the spreadsheet UI it is the active sheet.