Class ServerHandler


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 ClientHandlers but they are not limited in what they can do.

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 Hidden field to your app storing the information you want to save and pass it back explicitly to handlers as a "callback element."

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

Send feedback about...

Apps Script
Apps Script
Need help? Visit our support page.