Reputation: 2093
I have a GA script, say, s1
.
s1
has 3 functions, f1
, f2
and f3
.
I want to set trigger for f1
(which is in s1
) from another script s2
.
Is it possible to do it?
If yes, how to do it? How to refer to f1
from s2
?
The apps documentation on "managing triggers programmatically" says that you need to give function name to set a trigger as given below.
// One-time execution only
// Use JavaScript Date of 5/17/2012
var date = new Date(2012, 5, 17);
var oneTimeOnly = ScriptApp.newTrigger("runCommand")
.timeBased()
.at(date)
.create();
It seems, the function "runCommand" must be in the same file.
I also read the documentation about libraries. I have included the script s1
in s2
. I can also call methods in s1
like s1.f1
, s1.f2
from s2
. But I cannot set the trigger.
When I executed:
var date = new Date(2014, 2, 17);
var oneTimeOnly = ScriptApp.newTrigger("s1.f1")
.timeBased()
.at(date)
.create();
I got the error: The selected function cannot be found.
Upvotes: 1
Views: 812
Reputation: 324
Triggers can only be created for local functions in the project. In order to accomplish what you want you need to create a wrapper function for the library function in the project
Upvotes: 2