问题
i looked at the google app script installable trigger docs online (https://developers.google.com/apps-script/support) , and one of the examples shows how 2 create 2 time 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();
}
My code:
function createTimeDrivenTriggers() {
// Trigger every 1 hours.
ScriptApp.newTrigger('MainFunctionDaily')
.timeBased()
.everyHours(1)
.create();
// Trigger every Friday at 13:00.
ScriptApp.newTrigger('MainFunctionWeekly')
.timeBased()
.onWeekDay(ScriptApp.WeekDay.FRIDAY)
.atHour(13)
.create();
}
However when i try to create the triggers, i get an error:
This add-on has created too many time-based triggers in this document for this Google user account
Please advise
回答1:
UPDATE: The documentation for add-ons was moved. In this case the new location of the below referred restriction is https://developers.google.com/gsuite/add-ons/concepts/editor-triggers
On Google Apps Scripts add-ons it's not possible to create two triggers of the same type on the same document by a function ran on behalf of the same user.
From https://developers.google.com/apps-script/guides/triggers/installable#limitations (emphasis mine):
Limitations
Several limitations apply to installable triggers in add-ons:Each add-on can only have one trigger of each type, per user, per document. For instance, in a given spreadsheet, a given user can only have one edit trigger, although the user could also have a form-submit trigger or a time-driven trigger in the same spreadsheet.
The alternatives are
- Use different accounts to create each trigger.
- Create several add-ons one for each required trigger
- Use a regular script rather than an add-on.
回答2:
Two possible issues:
- Your triggers are contradicting each other
- You may need to add a create function before the second trigger.
You will probably need to choose one of your triggers only but you can try this:
function createTimeDrivenTriggers() {
// Trigger every 6 hours.
ScriptApp.newTrigger('myFunction')
.timeBased()
.everyHours(6)
.create();
}
function createTimeDrivenTriggers() {
// Trigger every Monday at 09:00.
ScriptApp.newTrigger('myFunction')
.timeBased()
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.atHour(9)
.create();
}
来源:https://stackoverflow.com/questions/37204774/2-time-triggers-google-app-scripts