0
votes

I create Add-on for google spreadsheets. Is there a way to create a Trigger programmatically tied to the given spreadsheet. In the documentation I found a description of two classes SpreadsheetTriggerBuilder and ClockTriggerBuilder. But as far as I understand, I need something in between.

1
What does this "tying" do? Or what do you expect it to do? - TheMaster
Please provide more details on what you want to accomplish. Your question is very vague. - Iamblichus
I want create single time-based trigger for document where used my addon. For multiple users - user2987203

1 Answers

0
votes

You can create triggers in two ways:

  • manually

  • programmatically

However, since your main purpose is to create these triggers in an add-on, you should create them programmatically. Time-driven triggers are not tied to a particular spreadsheet, as they trigger the execution of a function.

So, creating a time-driven trigger should look something like this:

function createTimeDrivenTriggers() {
  ScriptApp.newTrigger('functionToDoSomething')
      .timeBased()
      .everyHours(1)
      .create();
}

The trigger above will trigger the execution of the functionToDoSomething function every hour.

Add-on triggers are also subject to restrictions, the most notable one being:

An add-on can use a time-driven trigger once per hour at most.

You might also benefit from taking a look at this documentation here.

Reference