I am creating a UI panel with buttons and text boxes for use on a Google site. It seems the script re-starts (Globals re-load, Logs clear) on occasion – as best I can figure it’s after hitting a button. There’s nothing in the button handler that causes an error. The button handler runs fine (the doGet does NOT seem to run again).
Using the following to set up the button handler. Maybe something here is causing it?
//container is the app
//textOnButton = "Next"
//handler ="submitNext_" - name of method that handles click
//vPanel is the panel containing the button
var submitButton = container.createButton().setId(textOnButton);
submitButton.setText(textOnButton);
// submit handlers
var submitServerHandler = container.createServerClickHandler(handler);
submitServerHandler.addCallbackElement(vPanel);
submitButton.addClickHandler(submitServerHandler);
Any ideas about this behavior? The main problem is a couple of my global constants aren’t really constants and they get re-set on this restart. I can store them in UserProperties as a work-around but wanted to understand why this was happening.
This is intentional behavior. Each callback runs a “fresh” script, and as such it is not advisable to have constants that aren’t really constants. See the class documentation here:
https://developers.google.com/apps-script/class_serverhandler
Serge, those methods are deprecated simply because we replaced them all with createServerHandler which works for any type of handler. All of the old wordy createServerXXXHandler methods still work; they are just synonyms for createServerHandler.