Server Scripts and Events
8 min
server scripts allow you to control form behaviour during key points in the form lifecycle they can be used to initialise data, respond to form submissions, define complex data sources, and apply custom logic where required form lifecycle methods activate web forms support several server side lifecycle methods each method runs at a different stage of the form process form init form init is called before any controls are created on the form use this method to prepare data before the form is rendered common uses include setting job arguments loading data sources preparing values used by controls applying conditional form behaviour before controls are generated example public void form init(activatehttprequest request) { job arguments setvalue("resource", "=//resources/configuration"); } form load form load is called after the controls have been loaded at this point, getcontrol() is available however, most form logic should be handled in form init, because it is usually better to prepare the data before controls are created rather than modify controls after they have loaded use form load only when you specifically need to work with controls after they exist example public void form load(object sender, eventargs e) { provisioningtrace forms("form load"); } form submit form submit is called when the form is submitted unlike earlier form behaviour, controls are not recreated during postback, so server controls are not available inside this method use form submit to respond to user actions and submission events common uses include handling button actions performing custom validation displaying page, control, or popup messages updating job arguments returning to a previous page redirecting to the next page example public void form submit(activatehttprequest request) { if (request iseventsource("validatename")) { string name = job arguments getstring("data/name"); request page setcontrolerror("txtname1", "can't find user \[" + name + "]"); } if (request iseventsource("sendemail")) { request page setpopupmessage("email sent"); } } using event sources event sources identify which form action triggered the submit event this allows a single form submit method to handle multiple actions cleanly example if (request iseventsource("generatepageerror")) { request page setpageerror("please select at least one user to request information from "); } use event source checks to separate submit logic by button, action, or form event server script availability the server script is available as a global variable within the form this can be used in the form definition for more advanced scenarios, such as complex data sources or conditional logic recommended approach use each lifecycle method for its intended purpose use form init to prepare data before controls are created use form load only when control level access is required use form submit to handle submitted actions use event sources to keep submit logic clear and maintainable best practice prefer setting data in form init and allowing controls to load from that data naturally avoid changing control properties in form load unless there is a specific reason to access the control directly keep form submit focused on handling user actions rather than preparing initial form data