Search code examples
google-apps-scriptgoogle-sheetstriggers

How to manage triggers for a Google Apps Script add-on


I am creating an Editor Addon that let me create automation tasks.

For example I want to be able to create tasks on the model Trigger-Condition-Action such as

When the spreadsheet '123', sheet 'Sheet1', is updated
If Column A equals "Done"
Copy the row to spreadsheet '789' sheet 'Sheet2'

Problem #1

Because Google imposes quota on the number of triggers I can create,

  • For Time based triggers, I am thinking storing them on a separate backend and update the sheet via the Sheets API when the time is reached.
  • For Edit triggers, they can be grouped into a single onEdit trigger per spreadsheet. But what if I create an Edit trigger on 20+ different spreadsheets?

Google limitation is 20 triggers / user / script.

Does it mean that a user using my addon will be limited to 20 spreadsheets?

Problem #2

For the task above, the action should be run only when the condition is met. On every onEdit, I need to check for the condition. If I store the user defined tasks on a separate backend, it means I have to call UrlFetch inside onEdit to check for the condition, which is very inefficient given how often onEdit runs.

Is there any best practice to do that without blowing up the 500 KB / property store quota?


Solution

  • Problem #1

    I couldn't find a strong reference but according to the comment from Cameron Roberts here

    Although I can't find the documentation, I believe each document in which the add-on is installed would be treated as an individual script, so you wouldn't be limited to 30 documents.

    Problem #2

    I will call UrlFetch inside an installable onOpen trigger to retrieve all the tasks of the user. Cache it and test the condition inside onEdit for every edit operation.