Class TriggerBuilder

TriggerBuilder

脚本触发器的通用构建器。

方法

方法返回类型简介
forDocument(document)DocumentTriggerBuilder创建并返回与指定文档绑定的 DocumentTriggerBuilder
forDocument(key)DocumentTriggerBuilder创建并返回与具有指定 ID 的文档关联的 DocumentTriggerBuilder
forForm(form)FormTriggerBuilder创建并返回与指定表单关联的 FormTriggerBuilder
forForm(key)FormTriggerBuilder创建并返回与具有指定 ID 的表单关联的 FormTriggerBuilder
forSpreadsheet(sheet)SpreadsheetTriggerBuilder创建并返回与指定电子表格关联的 SpreadsheetTriggerBuilder
forSpreadsheet(key)SpreadsheetTriggerBuilder创建并返回与具有指定 ID 的电子表格关联的 SpreadsheetTriggerBuilder
forUserCalendar(emailId)CalendarTriggerBuilder返回用于构建日历触发器的构建器。
timeBased()ClockTriggerBuilder创建并返回用于构建基于时间的触发器的 ClockTriggerBuilder

详细文档

forDocument(document)

创建并返回与指定文档关联的 DocumentTriggerBuilder

ScriptApp.newTrigger('myFunction')
  .forDocument(DocumentApp.getActiveDocument())
  .onOpen()
  .create();

参数

名称类型说明
documentDocument文档

弃踢回攻

DocumentTriggerBuilder - 新的 DocumentTriggerBuilder

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

forDocument(key)

创建并返回与具有指定 ID 的文档关联的 DocumentTriggerBuilder

ScriptApp.newTrigger('myFunction')
  .forDocument('1234567890abcdefghijklmnopqrstuvwxyz')
  .onOpen()
  .create();

参数

名称类型说明
keyString文档 ID

弃踢回攻

DocumentTriggerBuilder - 新的 DocumentTriggerBuilder

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

forForm(form)

创建并返回与指定表单关联的 FormTriggerBuilder

ScriptApp.newTrigger('myFunction')
  .forForm(FormApp.getActiveForm())
  .onFormSubmit()
  .create();

参数

名称类型说明
formForm表单

弃踢回攻

FormTriggerBuilder - 新的 FormTriggerBuilder

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

forForm(key)

创建并返回与具有指定 ID 的表单关联的 FormTriggerBuilder

ScriptApp.newTrigger('myFunction')
  .forForm('1234567890abcdefghijklmnopqrstuvwxyz')
  .onFormSubmit()
  .create();

参数

名称类型说明
keyString表单 ID

弃踢回攻

FormTriggerBuilder - 新的 FormTriggerBuilder

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

forSpreadsheet(sheet)

创建并返回与指定电子表格关联的 SpreadsheetTriggerBuilder

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

参数

名称类型说明
sheetSpreadsheet打开电子表格

弃踢回攻

SpreadsheetTriggerBuilder - 新的 文件触发器工具集

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

forSpreadsheet(key)

创建并返回与具有指定 ID 的电子表格关联的 SpreadsheetTriggerBuilder

ScriptApp.newTrigger('myFunction')
  .forSpreadsheet('1234567890abcdefghijklmnopqrstuvwxyz')
  .onEdit()
  .create();

参数

名称类型说明
keyString电子表格 ID

弃踢回攻

SpreadsheetTriggerBuilder - 新的 文件触发器工具集

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

forUserCalendar(emailId)

返回用于构建日历触发器的构建器。

参数

名称类型说明
emailIdString触发器监控的用户日历的电子邮件 ID。

弃踢回攻

CalendarTriggerBuilder - 新的 CalendarTriggerBuilder。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.googleapis.com/auth/calendar.events
  • https://www.googleapis.com/auth/calendar.events.readonly
  • https://www.google.com/calendar/feeds

timeBased()

创建并返回用于构建基于时间的触发器的 ClockTriggerBuilder

ScriptApp.newTrigger('myFunction')
  .timeBased()
  .atDate(2013, 10, 31)
  .create();

弃踢回攻

ClockTriggerBuilder - 新的 ClockTriggerBuilder

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/script.scriptapp