Class SpreadsheetTriggerBuilder

  • SpreadsheetTriggerBuilder is a builder used to create triggers for spreadsheets.

  • You can create triggers that fire on changes, edits, form submissions, or when the spreadsheet is opened.

  • The create() method finalizes and returns the trigger.

  • Methods like onChange(), onEdit(), onFormSubmit(), and onOpen() return the builder for method chaining.

Builder for spreadsheet triggers.

Detailed documentation

create()

Creates the trigger and returns it.

Return

Trigger — The created trigger.


onChange()

Specifies a trigger that will fire when the spreadsheet's content or structure is changed.

const sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger('myFunction').forSpreadsheet(sheet).onChange().create();

Return

SpreadsheetTriggerBuilder — a builder for chaining


onEdit()

Specifies a trigger that will fire when the spreadsheet is edited.

const sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger('myFunction').forSpreadsheet(sheet).onEdit().create();

Return

SpreadsheetTriggerBuilder — a builder for chaining


onFormSubmit()

Specifies a trigger that will fire when the spreadsheet has a form submitted to it.

const sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger('myFunction')
    .forSpreadsheet(sheet)
    .onFormSubmit()
    .create();

Return

SpreadsheetTriggerBuilder — A builder for chaining.


onOpen()

Specifies a trigger that will fire when the spreadsheet is opened.

const sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger('myFunction').forSpreadsheet(sheet).onOpen().create();

Return

SpreadsheetTriggerBuilder — a builder for chaining

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.