Class ClockTriggerBuilder

A builder for clock triggers

Methods

MethodReturn typeBrief description
after(durationMilliseconds)ClockTriggerBuilderSpecifies the duration (in milliseconds) after the current time that the trigger will run.
at(date)ClockTriggerBuilderSpecifies when the trigger will run (plus or minus 15 minutes).
atDate(year, month, day)ClockTriggerBuilderSpecifies trigger will fire on the given date, by default near midnight (+/- 15 minutes).
atHour(hour)ClockTriggerBuilderSpecifies the hour the trigger will run (plus or minus 15 minutes).
create()TriggerCreates the trigger.
everyDays(n)ClockTriggerBuilderSpecifies to run the trigger every n days.
everyHours(n)ClockTriggerBuilderSpecifies to run the trigger every n hours.
everyMinutes(n)ClockTriggerBuilderSpecifies to run the trigger every n minutes.
everyWeeks(n)ClockTriggerBuilderSpecifies to run the trigger every n weeks.
inTimezone(timezone)ClockTriggerBuilderSpecifies the timezone that the specified dates/time that the trigger will run in.
nearMinute(minute)ClockTriggerBuilderSpecifies the minute the trigger will run (plus or minus 15 minutes).
onMonthDay(day)ClockTriggerBuilderSpecifies on what date in the month that the trigger will run.
onWeekDay(day)ClockTriggerBuilderSpecifies on what day of the week that the trigger will run.

Detailed documentation

after(durationMilliseconds)

Specifies the duration (in milliseconds) after the current time that the trigger will run. (plus or minus 15 minutes).

 
// Creates a trigger that will run 10 minutes later
 ScriptApp.newTrigger("myFunction")
   .timeBased()
   .after(10 * 60 * 1000)
   .create();
 

Parameters

NameTypeDescription
durationMillisecondsIntegerthe duration (in milliseconds) after the current time when the trigger should run

Return

ClockTriggerBuilder — the builder for chaining


at(date)

Specifies when the trigger will run (plus or minus 15 minutes).

 
// Creates a trigger for December 1, 2012
 var triggerDay = new Date(2012, 11, 1);
 ScriptApp.newTrigger("myFunction")
   .timeBased()
   .at(triggerDay)
   .create();
 

Parameters

NameTypeDescription
dateDatea Date object representing when the trigger should run

Return

ClockTriggerBuilder — the builder for chaining


atDate(year, month, day)

Specifies trigger will fire on the given date, by default near midnight (+/- 15 minutes).

 
// Schedules for January 1st, 2013
 ScriptApp.newTrigger("myFunction")
   .timeBased()
   .atDate(2013, 1, 1)
   .create();
 

Parameters

NameTypeDescription
yearIntegerthe calendar year to schedule the trigger
monthIntegerthe calendar month to schedule the trigger (should be a number between 1 and 12, inclusive)
dayIntegerthe calendar day to schedule the trigger (should be a number between 1 and 31, inclusive)

Return

ClockTriggerBuilder — the builder for chaining


atHour(hour)

Specifies the hour the trigger will run (plus or minus 15 minutes).

 
// Runs at 5am in the timezone of the script
 ScriptApp.newTrigger("myFunction")
   .timeBased()
   .atHour(5)
   .everyDays(1) // Frequency is required if you are using atHour() or nearMinute()
   .create();
 

Parameters

NameTypeDescription
hourIntegerthe hour at which to fire

Return

ClockTriggerBuilder — the builder for chaining


create()

Creates the trigger.

Return

Trigger — the newly created, scheduled trigger


everyDays(n)

Specifies to run the trigger every n days.

 
ScriptApp.newTrigger("myFunction")
   .timeBased()
   .everyDays(3)
   .create();
 

Parameters

NameTypeDescription
nIntegerthe number of days between executions

Return

ClockTriggerBuilder — the builder for chaining


everyHours(n)

Specifies to run the trigger every n hours.

 
ScriptApp.newTrigger("myFunction")
   .timeBased()
   .everyHours(12)
   .create();
 

Parameters

NameTypeDescription
nIntegerthe number of hours between executions

Return

ClockTriggerBuilder — the builder for chaining


everyMinutes(n)

Specifies to run the trigger every n minutes. n must be 1, 5, 10, 15 or 30.

 
ScriptApp.newTrigger("myFunction")
   .timeBased()
   .everyMinutes(10)
   .create();
 

Parameters

NameTypeDescription
nIntegerthe number of minutes between executions

Return

ClockTriggerBuilder — the builder for chaining


everyWeeks(n)

Specifies to run the trigger every n weeks.

 
ScriptApp.newTrigger("myFunction")
   .timeBased()
   .everyWeeks(2)
   .create();
 

Parameters

NameTypeDescription
nIntegerthe number of weeks between executions

Return

ClockTriggerBuilder — the builder for chaining


inTimezone(timezone)

Specifies the timezone that the specified dates/time that the trigger will run in. By default, the timezone will be that of the script. The list of valid timezone strings corresponds with the valid timezone strings for TimeZone. An invalid timezone string will cause the script to throw an error.

 
// Schedule the trigger to execute at noon every day in the US/Pacific time zone
 ScriptApp.newTrigger("myFunction")
   .timeBased()
   .atHour(12)
   .everyDays(1)
   .inTimezone("America/Los_Angeles")
   .create();
 

Parameters

NameTypeDescription
timezoneStringthe timezone with which to treat time information in the event

Return

ClockTriggerBuilder

See also

  • TimeZone

nearMinute(minute)

Specifies the minute the trigger will run (plus or minus 15 minutes).

 
// Runs at approximately 5:30am in the timezone of the script
 ScriptApp.newTrigger("myFunction")
   .timeBased()
   .atHour(5)
   .nearMinute(30)
   .everyDays(1) // Frequency is required if you are using atHour() or nearMinute()
   .create();
 

Parameters

NameTypeDescription
minuteIntegerthe minute at which to fire

Return

ClockTriggerBuilder — the builder for chaining


onMonthDay(day)

Specifies on what date in the month that the trigger will run.

 
// Schedules for the first of every month
 ScriptApp.newTrigger("myFunction")
   .timeBased()
   .onMonthDay(1)
   .create();
 

Parameters

NameTypeDescription
dayIntegerthe day of the month the trigger should be scheduled for

Return

ClockTriggerBuilder — the builder for chaining


onWeekDay(day)

Specifies on what day of the week that the trigger will run.

 
ScriptApp.newTrigger("myFunction")
   .timeBased()
   .onWeekDay(ScriptApp.WeekDay.FRIDAY)
   .create();
 

Parameters

NameTypeDescription
dayWeekdaythe day of the week to fire

Return

ClockTriggerBuilder — the builder for chaining

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.