Form API - ServiceNow Fluent
The Form API defines forms [sys_ui_form] that display information for records in the classic environment.
For general information about forms, see ServiceNow AI Platform® form administration.
Form object
Configure a form [sys_ui_form] to display information for records in a table.
| Name | Type | Description |
|---|---|---|
| table | String | Required. The name of the table to which the form applies. |
| view | Reference or String | Required. The variable identifier or name of the UI view [sys_ui_view] which applies, or the default view. To define a UI view, use the Record API - ServiceNow Fluent. To use the default view ( default_view), you must import
it: |
| sections | Array | Required. A list of form sections [sys_ui_section] that define how fields are grouped and displayed in the form. For more information, see sections array. |
| user | Reference or String | The variable identifier or name of the user [sys_user] who created the form. To define a user, see Record API - ServiceNow Fluent. |
| roles | Array | A list of variable identifiers of Role objects or names of roles that can access the form. For more information, see Role API - ServiceNow Fluent. |
| $meta | Object | Metadata for the application metadata. With the installMethod property, you can map the application metadata to an output directory that loads only in specific
circumstances. Valid values for installMethod:
|
| $override | Object | Fields and their values provided to configure fields that aren't included in a ServiceNow Fluent API or to override an existing field. Warnung: Type safety isn't enforced for fields configured with the $override property. |
import { Form } from '@servicenow/sdk/core'
Form({
table: 'sn_formredesign_rd',
view: advancedView,
sections: [
{
caption: '',
fields: [
['name', 'date' ],
['priority', 'state'],
],
},
{
caption: 'Notes',
fields: ['comments', 'work_notes'],
},
],
})
import { Record } from '@servicenow/sdk/core'
export const advancedView = Record({
$id: Now.ID['adv-view'],
table: 'sys_ui_view',
data: {
name: 'advanced_view',
title: 'Advanced View',
},
})sections array
Configure a section in a form [sys_ui_section] that defines how fields are grouped and displayed in the form.
The sections array is a property within the Form object. Users can expand or collapse form sections to show or hide the fields they need. If a user has tabs enabled, each form section appears on a separate tab.
| Name | Type | Description |
|---|---|---|
| caption | String | Required. A title for the section. |
| fields | Array | Required. A list of fields to include in the section [sys_ui_element]. For more information, see fields array. |
| $id | String or Number | A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys_id. For more information, see ServiceNow Fluent language constructs. Format: |
| header | Boolean | Flag that indicates whether to display a header. Valid values:
Default: false |
sections: [
{
caption: '',
fields: [
['name', 'date' ],
['priority', 'state'],
],
},
{
caption: 'Notes',
fields: ['comments', 'work_notes'],
},
],
fields array
Specify the fields to include in a form section [sys_ui_element].
The fields array is a property within the Form object and supports up to two fields in each row and types that provide layout control.
| Name | Type | Description |
|---|---|---|
| element | String | Required. The name of a field. |
| position | Number | The position of the field in the section in relation to other fields. |
| type | String | A layout type for the field. Valid values:
|
| formatter | String | A formatter [sys_ui_formatter] for the field. A formatter is a form element used to display information that is not a field in the record. For more information about formatters, see Using formatters. |
Fields can be provided as objects or arrays with the following syntax.
fields: [
{
element: 'date', // Single field as an object with formatting
position: 1,
type: '.split',
formatter: 'Access Control Rules Explanation'
},
['.space', {element: 'name', position: 3}], // Single field as an object preceded by an empty space
['sys_updated_on', 'sys_updated_by'], // Group fields horizontally in the same row
]