Access and manipulate script publishing and triggers. This class allows users to create script triggers and control publishing the script as a service.
Properties
Property | Type | Description |
---|---|---|
EventType | EventType | |
TriggerSource | TriggerSource | |
WeekDay | Weekday |
Methods
Method | Return type | Brief description |
---|---|---|
deleteTrigger(trigger) | void | Removes the given trigger so it will no longer run. |
getProjectTriggers() | Trigger[] | Returns an array of triggers associated with the current project. |
getService() | Service | Returns a Service object to manage publishing the script as a web app. |
invalidateAuth() | void | Invalidates the authorization this user has to execute the current script. |
newTrigger(functionName) | TriggerBuilder | Begins the process of creating a trigger that when fired, will call the passed in method. |
Detailed documentation
deleteTrigger(trigger)
Removes the given trigger so it will no longer run.
// This code deletes all the triggers
var triggers = ScriptApp.getProjectTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
Parameters
Name | Type | Description |
---|---|---|
trigger | Trigger | the trigger to delete |
getProjectTriggers()
Returns an array of triggers associated with the current project.
Logger.log("current project has " + ScriptApp.getProjectTriggers().length + " triggers");
Return
Trigger[]
— all the triggers that this script owns
getService()
Returns a Service object to manage publishing the script as a web app.
// get the url of the published service
var url = ScriptApp.getService().getUrl();
Return
Service
— an object used to observe and control script service publishing
invalidateAuth()
Invalidates the authorization this user has to execute the current script. Used to invalidate any permissions for the current script. This is especially useful for functions tagged as one-shot authorization. Since one-shot authorization functions can only be called the first run after the script has acquired authorization, if you wish to perform an action afterwards, you will have to revoke any authorization the script had, so the user can see the authorization dialog again.
ScriptApp.invalidateAuth();
newTrigger(functionName)
Begins the process of creating a trigger that when fired, will call the passed in method.
// creates an onEdit trigger for a spreadsheet identified by id
ScriptApp.newTrigger("myFunction").forSpreadsheet("id of my spreadsheet").onEdit().create();
Parameters
Name | Type | Description |
---|---|---|
functionName | String | the function to call when the trigger fires |
Return
TriggerBuilder
— an object used to continue the trigger building process