Access and manipulate script publishing.
Properties
Property | Type | Description |
---|---|---|
Restriction | Service.Restriction | Enum representing the access restrictions on a script exported as a service. |
Methods
Method | Return type | Brief description |
---|---|---|
disable() | void | Disables the script from being accessed as a web app. |
enable(restriction) | void | Allows the script to be accessed as a web app with the specified permissions. |
getUrl() | String | Returns the URL of the web app, if it has been deployed; otherwise returns null . |
isEnabled() | Boolean | Returns true if the script is accessible as a web app. |
Detailed documentation
disable()
Disables the script from being accessed as a web app. This method is equivalent to opening the "Publish > Deploy as web app" dialog and clicking "disable web app".
ScriptApp.getService().disable();
enable(restriction)
Allows the script to be accessed as a web app with the specified permissions. This method is
equivalent to opening the "Publish > Deploy as web app" dialog and clicking "Deploy".
You can either share to yourself with Restriction.MYSELF
, share to the domain with
Restriction.DOMAIN
, or share to everyone with Restriction.ALL
. Not all sharing
modes are valid in all domains. The URL for the published app can be obtained by calling
ScriptApp.getService().getUrl()
. Note: this method works only in the script execution
that immediately follows authorization. If you want to call this method on a subsequent
execution, you must first invalidate the script's authorization by calling
ScriptApp.invalidateAuth()
, then have the user re-run the script and re-authorize. Also
note that at least one version of the script must be
saved before this method will work.
var service = ScriptApp.getService();
service.enable(service.Restriction.ALL);
// Other options are:
// Restriction.DOMAIN
// Restriction.MYSELF
Parameters
Name | Type | Description |
---|---|---|
restriction | Service.Restriction | who is allowed to access the web app |
getUrl()
Returns the URL of the web app, if it has been deployed; otherwise returns null
.
// Mail the URL of the published web app.
MailApp.sendMail("[email protected]", "My Snazzy App",
"My new app is now available at " + ScriptApp.getService().getUrl());
Return
String
— the URL of the web app
isEnabled()
Returns true
if the script is accessible as a web app.
var svc = ScriptApp.getService();
// Publish the script as a web app if it isn't currently.
if (!svc.isEnabled()) {
svc.enable(svc.Restriction.MYSELF);
}
Return
Boolean
— true
if the script is published as a web app; false
if not