Docs
On this page
reference2 min readApplication: Platform

UI events

Fields of a UI event, which runs a script in the browser when a form loads, a field changes or a form is saved, with examples.

A UI event runs a script in the user’s browser while a form is open, for example to make a field required or to fill one field from another. This page lists a UI event’s fields and gives examples, for administrators and developers with the administrator role and JavaScript knowledge.

In the Administration workspace, go to Scripting & automation → Scripts → UI event. A UI event can show, hide and require fields and form elements. To read server data it calls a system controller or the REST API. See Where scripts run.

The UI event item in the Scripts section of the Scripting & automation menu.

UI event fields

The empty Create UI event form.
Field Type Behaviour Purpose
Name Text Identifies the UI event, for example “Incident - Set Requested for based on selected Requestor”.
Event type Choice Field event or Form event. Whether the event follows one field or the whole form.
Event name Choice Values are in the next table. The moment the script runs.
Active Yes or no Default yes. Only active UI events run.
Table Table The form the event runs on.
Field Field Shown for a field event. The field whose change runs the script.
Description Text Says what the event does, for other administrators.
Script Script Receives current, viewAspect and isLoading. The logic to run.

Event name values

Event name Event type Runs
On form load Form event When the form has finished loading.
On change Field event When the form loads and when the field’s value changes. Check isLoading to tell the two apart.
On click Field event When the user selects the field’s control.
On form submit Form event When the user saves the form. Return false to stop the save. Returning nothing allows it.
On relation update Field event When entries are added to or removed from a related list.
On related list Form event or field event When a related list loads or changes page. A form event runs for every related list, a field event for one. The script also gets listAction, listData and listRecordCount.

Script variables

Variable Purpose
current The record on the form. See Client form API.
viewAspect The view aspect the form is shown in, such as ServiceDesk. See View aspects.
isLoading true while the form is loading.

current.getUIElements() returns a form layout element by its Form ID. Call visible(true) or visible(false) on it to show or hide it, and selectTab() to select a tab. In Form Builder, a container’s Form ID is its Identifier, under Advanced layout.

setFocus() on a field puts the cursor in it, first opening any tab that hides it. It returns false if the field is hidden or not on the form. For example, current.Description.setFocus();.

Example: require the assignee in one view

This form event makes Assignee required for the ServiceDesk view once the incident has left New. It hides Assignee in every other view.

Field Value
Event type Form event
Event name On form load
Table Incident
if (viewAspect == "ServiceDesk" && current.WorkflowStatus() != "new") {
    current.Assignee.visible(true);
    current.Assignee.required(true);
} else {
    current.Assignee.required(false);
    if (viewAspect != "ServiceDesk") {
        current.Assignee.visible(false);
    }
}

Example: show a section when the status is completed

This form event shows a container with the identifier completion_section only when the record is Completed.

if (current.WorkflowStatus() == "completed") {
    current.getUIElements("completion_section").visible(true);
} else {
    current.getUIElements("completion_section").visible(false);
}

Example: set the location from the requestor

This field event runs when Requestor changes on an incident. If Location is empty, it fills it with the requestor’s location. A UI event cannot query the User table itself, so it asks the server.

Field Value
Event type Field event
Event name On change
Table Incident
Field Requestor

With a REST call:

if (!isLoading && current.Requestor.hasValue() && !current.Location.hasValue()) {
    REST.get("User", current.Requestor(), { fields: "Location" })
        .then(response => {
            current.Location(response.data.Location);
        });
}

With a system controller named UserInfoController:

if (!isLoading && current.Requestor.hasValue() && !current.Location.hasValue()) {
    var requestObj = {};
    requestObj.userId = current.Requestor();

    WS.controller("UserInfoController", requestObj)
        .done(function(response) {
            current.Location(String(response.data.locationID));
        }).fail(function(response) {
            console.log(response);
        });
}

The controller script returns the location in answer:

answer = {};
if (userId) {
    let userRec = Table("User", userId);
    if (userRec && userRec.Location.hasValue()) {
        answer.locationID = userRec.Location.value();
    }
}
answer;

See Custom endpoints.

Last updated 3 December 2026commit 6777698daac5Chris Jones
Back to top