Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add time-driven triggers programmatically #16

Open
chriskyfung opened this issue Jul 9, 2021 · 0 comments
Open

✨ Add time-driven triggers programmatically #16

chriskyfung opened this issue Jul 9, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@chriskyfung
Copy link
Owner

The current version requires users to create their time-driven triggers manually from their Apps Script dashboard.

In fact, the time-driven triggers can be also created and deleted triggers programmatically with the Script service. Start by calling ScriptApp.newTrigger(functionName), which returns a TriggerBuilder.

The following example shows how to create two time-driven triggers—one that fires every 6 hours, and one that fires every Monday at 9 a.m. (in the time zone that your script is set to).

/**
 * Creates two time-driven triggers.
 */
function createTimeDrivenTriggers() {
  // Trigger every 6 hours.
  ScriptApp.newTrigger('myFunction')
      .timeBased()
      .everyHours(6)
      .create();

  // Trigger every Monday at 09:00.
  ScriptApp.newTrigger('myFunction')
      .timeBased()
      .onWeekDay(ScriptApp.WeekDay.MONDAY)
      .atHour(9)
      .create();
}

Reference: Managing triggers programmatically | Google Developers

New users can set up our script more easily, if a new function for trigger creation is added.

@chriskyfung chriskyfung added the enhancement New feature or request label Jul 9, 2021
@chriskyfung chriskyfung changed the title Add time-driven triggers programmatically ✨ Add time-driven triggers programmatically Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant