---
title: "UI events"
site: admin
version: 1.11
versions: "all"
url: https://docs-new.servicely.ai/admin/1.11/automation/ui-events/
type: reference
application: platform
last_updated: 2026-10-18
commit: f37120b6b82b
---


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.

UI events are under **Administration → Business Logic → 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](page:automation/scripting-overview).

## UI event fields

| 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

<!-- source: platform/data/AvailableValue?Table=UIEvent&Field=EventName -->

| 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 [UNVERIFIED] | When the user selects the field's control. [UNVERIFIED] |
| 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 [UNVERIFIED] | When a related list on the form is used. [UNVERIFIED] |

## Script variables

| Variable | Purpose |
| --- | --- |
| `current` | The record on the form. See [Client form API](page:api/scripting/client-form-api). |
| `viewAspect` | The view aspect the form is shown in, such as `ServiceDesk`. See [View aspects](page:data-model/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.

## 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 |

```javascript
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 field set container with the form ID `completion_section` only when the record is Completed.

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

<Image src="asset:screenshots/admin/automation-ui-events/image.png" size="36">The configuration of a field set container, with completion_section in Form ID.</Image>

## 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:

```javascript
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`:

```javascript
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`:

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

See [Custom endpoints](page:api/rest/custom-endpoints).

## Related

- [Where scripts run](page:automation/scripting-overview)
- [Triggers](page:automation/triggers)
- [Client form API](page:api/scripting/client-form-api)
- [View aspects](page:data-model/view-aspects)
