Google Apps Script
Feedback on this document

Class ScriptApp

Access and manipulate script publishing and triggers. This class allows users to create script triggers and control publishing the script as a service.

Properties

PropertyTypeDescription
EventTypeEventType
TriggerSourceTriggerSource
WeekDayWeekday

Methods

MethodReturn typeBrief description
deleteTrigger(trigger)voidRemoves the given trigger so it will no longer run.
getProjectTriggers()Trigger[]Returns an array of triggers associated with the current project.
getService()ServiceReturns a Service object to manage publishing the script as a web app.
invalidateAuth()voidInvalidates the authorization this user has to execute the current script.
newTrigger(functionName)TriggerBuilderBegins 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

NameTypeDescription
triggerTriggerthe 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

NameTypeDescription
functionNameStringthe function to call when the trigger fires

Return

TriggerBuilder — an object used to continue the trigger building process

Deprecated methods

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.