Deprecated. The UI service was deprecated on December 11, 2014. To create user interfaces, use the HTML service instead.
An event handler that runs on the server. These will, in general, run much slower than
s but they are not limited in what they can do.
ClientHandler
Any method that accepts a "Handler" parameter can accept a ServerHandler.
When a ServerHandler is invoked, the function it refers to is called on the Apps Script server in a "fresh" script. This means that no variable values will have survived from previous handlers or from the initial script that loaded the app. Global variables in the script will be re-evaluated, which means that it's a bad idea to do anything slow (like opening a Spreadsheet or fetching a Calendar) in a global variable.
If you need to save state on the server, you can try using ScriptProperties or UserProperties.
You can also add a
field to your app storing the information you want to save
and pass it back explicitly to handlers as a "callback element."
Hidden
If you set validators on a ServerHandler, they will be checked before the handler calls the server. The server will only be called if the validators succeed.
If you have multiple ServerHandlers for the same event on the same widget, they will be called simultaneously.
Deprecated methods
Method | Return type | Brief description |
---|---|---|
|
| Adds a widget to this as a "callback element." |
| String | Returns the id that has been assigned to this object. |
| String | Gets the text tag of this . |
| String | Gets the type of this object. |
|
| Sets the name of the function to call when this handler is invoked. |
|
| Sets the id of this . |
|
| Sets the text tag of this . |
|
| Sets this handler to fire only if the given widget's value is a valid email address. |
|
| Sets this handler to fire only if the given widget's value can be interpreted as an integer. |
|
| Sets this handler to fire only if the given widget's value is a string whose length is between min and max. |
|
| Sets this handler to fire only if the given widget's value matches this regular expression. |
|
| Sets this handler to fire only if the given widget's value matches this regular expression. |
|
| Sets this handler to fire only if the given widget's value is not a valid email address. |
|
| Sets this handler to fire only if the given widget's value cannot be interpreted as an integer. |
|
| Sets this handler to fire only if the given widget's value is a string whose length is less than min or greater than max. |
|
| Sets this handler to fire only if the given widget's value does not match this regular expression. |
|
| Sets this handler to fire only if the given widget's value does not match this regular expression. |
|
| Sets this handler to fire only if the given widget's value cannot be interpreted as an number. |
|
| Sets this handler to fire only if the given widget's value is not one of the strings given in the options parameter. |
|
| Sets this handler to fire only if the given widget's value cannot be interpreted as a number that is between min and max. |
|
| Sets this handler to fire only if the given widgets have values that are not numbers, or that do not sum up to the given value. |
|
| Sets this handler to fire only if the given widget's value can be interpreted as a number. |
|
| Sets this handler to fire only if the given widget's value is one of the strings given in the options parameter. |
|
| Sets this handler to fire only if the given widget's value can be interpreted as a number and is between min and max. |
|
| Sets this handler to fire only if the given widgets have values that are numbers and sum up to the given value. |
Deprecated methods
addCallbackElement(widget)
addCallbackElement(widget)
Deprecated. This function is deprecated and should not be used in new scripts.
Adds a widget to this
as a "callback element."
ServerHandler
When a
is called, any widgets added here, as well as any current
child widgets of those widgets, are considered as callback elements. The value of each of these
widgets is added to the information sent to the script processing the event, as long as the
following two conditions are met:
ServerHandler
- The callback element has a "setName" method.
- A name has been set.
Here is an example of how this can be used:
function doGet() {
var app = UiApp.createApplication();
var textBox1 = app.createTextBox().setName("textBox1");
var textBox2 = app.createTextBox().setId("textBox2");
app.add(textBox1);
app.add(textBox2);
var textBox3 = app.createTextBox().setName("textBox3");
var panel = app.createFlowPanel();
panel.add(textBox3);
app.add(panel);
var button = app.createButton("a button");
var handler = app.createServerHandler("handlerFunction");
handler.addCallbackElement(textBox1)
.addCallbackElement(textBox2)
.addCallbackElement(panel)
button.addClickHandler(handler);
app.add(button);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// There's a lot of information in 'parameter' about the event too, but we'll focus here
// only on the callback elements.
var textBox1 = parameter.textBox1; // the value of textBox1
var textBox2 = parameter.textBox2; // undefined! setId is not the same as setName
var textBox3 = parameter.textBox3; // works! the parent "panel" was a callback element
}
Parameters
Name | Type | Description |
---|---|---|
widget |
| the callback element. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
getId()
getId()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the id that has been assigned to this object.
This can be used in conjunction with app.getElementById() to retrieve a reference to this object.
Return
String
— the id that has been assigned to this object
getTag()
getTag()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the text tag of this
.ServerHandler
Return
String
— the text tag.
getType()
getType()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the type of this object.
Return
String
— the object type
setCallbackFunction(functionToInvoke)
setCallbackFunction(functionToInvoke)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets the name of the function to call when this handler is invoked.
Parameters
Name | Type | Description |
---|---|---|
functionToInvoke | String | the name of the function to call. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
setId(id)
setId(id)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets the id of this
.ServerHandler
Parameters
Name | Type | Description |
---|---|---|
id | String | the new id, which can be used to retrieve the from
app.getElementById(id). |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
setTag(tag)
setTag(tag)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets the text tag of this
.ServerHandler
Parameters
Name | Type | Description |
---|---|---|
tag | String | the new text tag, which can be anything you wish to store with the widget. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateEmail(widget)
validateEmail(widget)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value is a valid email address. This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateInteger(widget)
validateInteger(widget)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value can be interpreted as an integer.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateLength(widget, min, max)
validateLength(widget, min, max)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value is a string whose length is between min and max.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
min | Integer | the minimum length. If null, no minimum is enforced. |
max | Integer | the maximum length. If null, no maximum is enforced. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateMatches(widget, pattern)
validateMatches(widget, pattern)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value matches this regular expression.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
pattern | String | the regex to test, as a string. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateMatches(widget, pattern, flags)
validateMatches(widget, pattern, flags)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value matches this regular expression.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
pattern | String | the regex to test, as a string. |
flags | String | regex flags. The only valid characters in this string are 'g', 'm', and 'i'. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotEmail(widget)
validateNotEmail(widget)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value is not a valid email address.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotInteger(widget)
validateNotInteger(widget)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value cannot be interpreted as an integer.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotLength(widget, min, max)
validateNotLength(widget, min, max)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value is a string whose length is less than min or greater than max.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
min | Integer | the minimum length. If null, no minimum is enforced. |
max | Integer | the maximum length. If null, no maximum is enforced. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotMatches(widget, pattern)
validateNotMatches(widget, pattern)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value does not match this regular expression.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
pattern | String | the regex to test, as a string. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotMatches(widget, pattern, flags)
validateNotMatches(widget, pattern, flags)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value does not match this regular expression.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
pattern | String | the regex to test, as a string. |
flags | String | regex flags. The only valid characters in this string are 'g', 'm', and 'i'. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotNumber(widget)
validateNotNumber(widget)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value cannot be interpreted as an number.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotOptions(widget, options)
validateNotOptions(widget, options)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value is not one of the strings given in the options parameter.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
options | String[] | the list of unacceptable values |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotRange(widget, min, max)
validateNotRange(widget, min, max)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value cannot be interpreted as a number that is between min and max.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
min | Number | the minimum length. If null, no minimum is enforced. |
max | Number | the maximum length. If null, no maximum is enforced. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNotSum(widgets, sum)
validateNotSum(widgets, sum)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widgets have values that are not numbers, or that do not sum up to the given value.
This will cause an error if any of the widgets do not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widgets |
| an array of the widgets to validate on. |
sum | Integer | the sum to validate with |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateNumber(widget)
validateNumber(widget)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value can be interpreted as a number.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateOptions(widget, options)
validateOptions(widget, options)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value is one of the strings given in the options parameter.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
options | String[] | the list of acceptable values |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateRange(widget, min, max)
validateRange(widget, min, max)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widget's value can be interpreted as a number and is between min and max.
This will cause an error if the widget does not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widget |
| the widget to validate on. |
min | Number | the minimum length. If null, no minimum is enforced. |
max | Number | the maximum length. If null, no maximum is enforced. |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler
validateSum(widgets, sum)
validateSum(widgets, sum)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets this handler to fire only if the given widgets have values that are numbers and sum up to the given value.
This will cause an error if any of the widgets do not have a text property.
Parameters
Name | Type | Description |
---|---|---|
widgets |
| an array of the widgets to validate on. |
sum | Integer | the sum to validate with |
Return
— the ServerHandler
itself, useful for chaining.ServerHandler