ServiceNow Fluent
Summarize
Summary of ServiceNow Fluent
ServiceNow Fluent is a declarative domain-specific language (DSL) based on TypeScript for defining application metadata files ([sysmetadata]) in ServiceNow. It enables developers to define metadata such as tables, roles, ACLs, business rules, and Automated Test Framework tests programmatically in source code rather than through forms or UI builders. This approach supports streamlined application development using the ServiceNow IDE or ServiceNow SDK.
Show less
ServiceNow Fluent supports two-way synchronization, allowing metadata changes made in the ServiceNow AI Platform user interfaces to sync back to source code, and vice versa, ensuring consistency across development environments.
Key Features
- Declarative Metadata Definition: Use ServiceNow Fluent APIs to define metadata types with concise TypeScript code, improving clarity and reducing manual UI configuration.
- Two-Way Sync: Changes to metadata or source code automatically synchronize bi-directionally between the instance and source code files (.now.ts).
- API Coverage: Includes dedicated APIs for common metadata types and a generic Record API for metadata without dedicated support. Some metadata types (e.g., Metadata Snapshots and UX Assets) remain as XML files.
- Integration with JavaScript Modules: Server-side scripts like Business Rules can import and use functions from JavaScript modules, supporting modular code reuse.
- Code Directives for Sync Control: Use @fluent-ignore, @fluent-disable-sync, and @fluent-disable-sync-for-file directives to manage diagnostic warnings and sync behavior for specific code lines or files.
Practical Usage
Developers write ServiceNow Fluent code in files with the .now.ts extension, importing APIs from @servicenow/sdk/core and defining application metadata objects such as tables, client scripts, and business rules. For example, a table with columns, a client script that shows an info message on record load, and a business rule that logs state changes can be defined succinctly in code.
When the application is built, the Fluent code generates corresponding metadata files on the ServiceNow instance, enabling version control, code review, and automated deployments.
Benefits for ServiceNow Customers
- Improved Developer Efficiency: Define complex metadata programmatically with fewer lines of code and without navigating UI forms.
- Enhanced Synchronization: Keep source code and instance metadata in sync automatically, reducing errors and manual reconciliation.
- Modular and Maintainable Code: Leverage TypeScript and JavaScript modules for clean, reusable server-side and client-side scripts.
- Better Version Control: Store metadata definitions as source code files, enabling standard software development practices such as branching and pull requests.
Getting Started
To begin using ServiceNow Fluent, customers should refer to the ServiceNow IDE or ServiceNow SDK documentation. The Fluent API reference and SDK examples repository provide detailed API information and code samples.
Define application metadata in source code using the ServiceNow Fluent domain-specific programming language.
Overview of ServiceNow Fluent
ServiceNow Fluent is a declarative, domain-specific language (DSL) based on TypeScript for defining the metadata files [sys_metadata] that make up applications and includes APIs for the different types of metadata, such as tables, roles, ACLs, business rules, and Automated Test Framework tests.
Developers define this metadata in a few lines of code instead of through a form or builder tool user interface. Applications created or converted with the ServiceNow IDE or ServiceNow SDK support development in ServiceNow Fluent.
ServiceNow Fluent supports two-way synchronization, which allows changes to metadata to be synced from other ServiceNow AI Platform user interfaces into source code and changes to source code to be synced back to metadata across the instance.
To get started using the ServiceNow IDE or ServiceNow SDK, see the ServiceNow IDE or ServiceNow SDK documentation.
ServiceNow Fluent APIs
ServiceNow Fluent includes APIs for many types of metadata. You can use the Record API to define application metadata that doesn't have a dedicated API. For the latest list of supported APIs and examples, see the ServiceNow Fluent API reference and ServiceNow SDK examples repository on GitHub.
ServiceNow Fluent usage
In files with the .now.ts extension, use objects in the ServiceNow Fluent APIs to define metadata in the application. You must also include the required imports for the APIs from @servicenow/sdk/core. For objects with server-side scripts, such as the BusinessRule object, you can import and use code from JavaScript modules.
import '@servicenow/sdk/global'
import { BusinessRule, ClientScript, DateColumn, StringColumn, Table } from '@servicenow/sdk/core'
import { showStateUpdate } from '../server/script.js'
//creates todo table, with three columns (deadline, status and task)
export const x_snc_example_to_do = Table({
name: 'x_snc_example_to_do',
schema: {
deadline: DateColumn({ label: 'Deadline' }),
state: StringColumn({
label: 'State',
choices: {
ready: { label: 'Ready' },
completed: { label: 'Completed' },
inProgress: { label: 'In Progress' },
},
}),
task: StringColumn({ label: 'Task', maxLength: 120 }),
},
})
//creates a client script that pops up 'Table loaded successfully!!' message everytime todo record is loaded
ClientScript({
$id: Now.ID['cs0'],
name: 'my_client_script',
table: 'x_snc_example_to_do',
active: true,
appliesExtended: false,
global: true,
uiType: 'all',
description: 'Custom client script generated by Now SDK',
isolateScript: false,
type: 'onLoad',
script: Now.include('../client/client-script.js'),
})
//creates a business rule that pops up state change message whenever a todo record is updated
BusinessRule({
$id: Now.ID['br0'],
action: ['update'],
table: 'x_snc_example_to_do',
script: showStateUpdate,
name: 'LogStateChange',
order: 100,
when: 'after',
active: true,
})function onLoad() {
g_form.addInfoMessage("Table loaded successfully!!")
}import { gs } from '@servicenow/glide'
export function showStateUpdate(current, previous) {
const currentState = current.getValue('state')
const previousState = previous.getValue('state')
gs.addInfoMessage(`state updated from "${previousState}" to "${currentState}"`)
}After building the application, this source code generates the following application metadata files on the instance.
@fluent-ignore: Suppresses ServiceNow Fluent diagnostic warnings and errors in the following line of code.@fluent-disable-sync: Turns off syncing changes to a ServiceNow Fluent object. Use before a call expression (for example,Record({ ... })) to turn off syncing for that object and its child objects. Only use this directive if you want to ignore changes made outside of the source code to the object and never update it when syncing.@fluent-disable-sync-for-file: Turns off syncing changes to a ServiceNow Fluent file (.now.ts). Use in the first line of the file to turn off syncing for all code in the file. Only use this directive if you want to ignore changes made outside of the source code to the file and never update it when syncing.