---
title: "Client form API"
site: api
version: 1.11
versions: "all"
url: https://docs-new.servicely.ai/api/1.11/scripting/client-form-api/
type: reference
application: platform
last_updated: 2026-12-02
commit: f6d7027b3395
---


In a client script, such as a UI event, `current` is the record open on the form. Use it to read and set field values, change how fields behave and show or hide layout elements while the user works on the form.

## Get an instance

`current` is ready to use. Each field of the record is a function on it, named as the field is named.

```javascript
// Read the value. For a reference field this is the record ID.
let requestedFor = current.RequestedFor();

// Read the display value. For a reference field this is the name.
let requestedForName = current.RequestedFor.displayValue();

// Set the value
current.ShortDescription("<short description>");

// Call a field function
current.RequestedFor.required(true);
```

A field that is not on the form still answers. Its functions do nothing and return null or false, and `existsOnForm()` returns false.

## Field functions

Call these as `current.<FieldName>.<function>()`. A function that takes a boolean sets the state when you pass one and returns the current state when you do not.

| Method | Returns | Description | Since |
| --- | --- | --- | --- |
| `visible(show)` | Boolean | Shows or hides the field. | 1.11 |
| `required(isRequired)` | Boolean | Makes the field mandatory or optional. | 1.11 |
| `readOnly(isReadOnly)` | Boolean | Makes the field read-only or editable. | 1.11 |
| `ignoreHasChanged(ignore)` | Boolean | When true, a script can set the field without marking the form as changed. | 1.11 |
| `displayValue()` | String | The display value. For a reference field this is the referenced record's name. | 1.11 |
| `displayValue(text)` | Nothing | Sets the display value. | 1.11 |
| `getValue()` | Any | The value, the same as `current.<FieldName>()`. | 1.11 |
| `hasValue()` | Boolean | True when the field has a value. | 1.11 |
| `isEmpty()` | Boolean | True when the field has no value. | 1.11 |
| `hasChanged()` | Boolean | True when the value has changed since the form loaded. | 1.11 |
| `existsOnForm()` | Boolean | True when the field is on the form. | 1.11 |
| `fieldName()` | String | The field name. | 1.11 |
| `fieldLabel()` | String | The field label, in the user's language. | 1.11 |
| `fieldType()` | String | The field type. | 1.11 |
| `setCssClass(className)` | Nothing | Sets a CSS class on the field, for example a class from a portal style. | 1.11 |
| `getCssClass()` | String | The CSS class set on the field. | 1.11 |
| `setStyle(property, value)` | Nothing | Sets one CSS style property on the field. | 1.11 |
| `field()` | Field | The underlying field object. | 1.11 |


## Record functions

Call these on `current` itself.

| Method | Returns | Description | Since |
| --- | --- | --- | --- |
| `getID()` | String | The record ID. | 1.11 |
| `isNewRecord()` | Boolean | True when the record has not been saved yet. | 1.11 |
| `getTableName()` | String | The table name. | 1.11 |
| `getTableDisplayName()` | String | The table name in the user's language. | 1.11 |
| `hasField(name)` | Boolean | True when the form holds the field. | 1.11 |
| `getFieldValue(name)` | Any | The value of the named field. | 1.11 |
| `setFieldValue(name, value)` | TableRecord | Sets the value of the named field. | 1.11 |
| `hasChanged()` | Boolean | True when any field has changed since the form loaded. | 1.11 |
| `hasChangedForNotIgnoredFields()` | Boolean | The same, leaving out fields set to ignore changes. | 1.11 |
| `hasChangedFor(filter)` | Boolean | The same, checking only the fields for which `filter(field)` returns true. | 1.11 |
| `saveRequiredState(onceOnly)` | Nothing | Remembers which fields are mandatory. With `onceOnly` true, a state already saved is kept. | 1.11 |
| `resetRequired()` | Nothing | Puts back the mandatory state that `saveRequiredState()` saved. | 1.11 |
| `getUIElements(formID)` | UI elements | The layout element with that **Form ID**, such as a heading, panel, container or tab. | 1.11 |

## Layout element functions

`getUIElements(formID)` finds a layout element that is not a field. Give the element a **Form ID** in the form builder first, then call these on the result.

| Method | Returns | Description | Since |
| --- | --- | --- | --- |
| `visible(show)` | Nothing | Shows the element when `show` is true and hides it when `show` is false. | 1.11 |
| `isVisible()` | Boolean | True when the element is shown. | 1.11 |
| `selectTab()` | Nothing | Makes the element the active tab. | 1.11 |
| `isTabActive()` | Boolean | True when the element is the active tab. | 1.11 |
| `addClass(className)` | Nothing | Adds a CSS class to the element. | 1.11 |
| `removeClass(className)` | Nothing | Removes a CSS class from the element. | 1.11 |
| `width(size)` | Nothing | Sets the element's width in the layout: `"one-third"`, `"two-thirds"`, `"half"` or `"full"`. | 1.11 |

One tab is always active. Hiding the active tab does not make another tab active, so call `selectTab()` on the tab you want.

## Examples

### Make a field mandatory for one value

```javascript
// <FieldName> is a field on the form
if (current.WorkflowStatus() == "<status code>") {
    current.<FieldName>.required(true);
} else {
    current.<FieldName>.required(false);
}
```

### Show a container and select a tab

```javascript
current.getUIElements("authentication-container").visible(true);
current.getUIElements("authentication-tab").selectTab();
```

### Check a field before you use it

<CodeTabs>
  Servicely Script

  ```javascript
  [
      current.RequestedFor.existsOnForm(),
      current.RequestedFor.fieldLabel(),
      current.RequestedFor.required()
  ];
  ```
</CodeTabs>

<CodeTabs>
  Response

  ```javascript
  [true, "<field label>", false]
  ```
</CodeTabs>

## Related

- [UI events](page:admin/automation/ui-events)
- [user and User](page:scripting/user)
- [Where scripts run](page:admin/automation/scripting-overview)
