ServiceNow Fluent

  • Release version: Xanadu
  • Updated July 31, 2025
  • 3 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of ServiceNow Fluent

    ServiceNow Fluent is a domain-specific language (DSL) based on TypeScript designed to define application metadata files ([sysmetadata]) in source code. It simplifies application development by allowing developers to specify metadata such as tables, roles, ACLs, business rules, and Automated Test Framework tests with concise code rather than using form or builder tool interfaces. ServiceNow Fluent supports two-way synchronization, enabling metadata changes to sync between ServiceNow AI Platform UIs and source code, ensuring consistency across the instance.

    Show full answer Show less

    Applications created or converted with the ServiceNow IDE or ServiceNow SDK support development using ServiceNow Fluent. Customers can start using it through these tools.

    ServiceNow Fluent APIs

    ServiceNow Fluent provides APIs for defining various metadata types, including but not limited to:

    • Access control lists (ACLs)
    • Application menus
    • Automated Test Framework tests
    • Business rules and client scripts
    • Cross-scope privileges
    • Dashboards and email notifications
    • Flows and import sets
    • Lists, properties, records, and roles
    • Script actions, script includes, scripted REST APIs
    • Service level agreements (SLAs)
    • Service portal widgets
    • Tables, UI actions, UI pages, UI policies, and workspaces

    For metadata types without dedicated APIs, the Record API can be used. Note that some metadata types like Metadata Snapshots and UX Assets cannot be represented as Fluent code and remain as XML files in the application metadata directory.

    Usage and Code Structure

    Developers write metadata definitions in files with the .now.ts extension using ServiceNow Fluent API objects. These files must import required APIs from @servicenow/sdk/core. Server-side scripts can import and use JavaScript modules to encapsulate reusable logic.

    An example includes defining a table with columns, a client script triggered on record load, and a business rule triggered on record update. Client scripts and business rules can reference external scripts and modules for organized code management.

    Practical Benefits and Workflow

    • Efficient Metadata Definition: Define complex application metadata with fewer lines of code.
    • Two-Way Synchronization: Seamlessly sync changes between source code and instance metadata to maintain consistency.
    • Modular and Reusable Code: Use JavaScript modules for server-side scripts, improving maintainability.
    • Improved Development Experience: Integrates with ServiceNow IDE and SDK for streamlined application development.

    Code Management Directives

    ServiceNow Fluent supports special comment directives to control diagnostics and synchronization behavior:

    • @fluent-ignore: Suppresses diagnostic warnings/errors for the next line of code.
    • @fluent-disable-sync: Disables syncing changes for a specific Fluent object and its children.
    • @fluent-disable-sync-for-file: Disables syncing for all Fluent code in a file.

    These directives help manage cases where metadata changes outside the source code should not be synced back.

    Next Steps for Customers

    • Use the ServiceNow IDE or SDK to start defining application metadata in source code with ServiceNow Fluent.
    • Refer to the ServiceNow Fluent API reference and SDK example repositories for guidance and code samples.
    • Leverage two-way synchronization to keep metadata consistent across source code and the instance.

    Define application metadata in source code using the ServiceNow Fluent domain-specific programming language.

    Overview of ServiceNow Fluent

    ServiceNow Fluent is a 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 the following types of metadata. You can use the Record API to define application metadata that doesn't have a dedicated API.

    For details about the APIs and examples, see ServiceNow Fluent API reference and the ServiceNow SDK examples GitHub repository.

    • Access control lists (ACLs)
    • Application menus
    • Automated Test Framework tests
    • Business rules
    • Client scripts
    • Cross-scope privileges
    • Dashboards
    • Email notifications
    • Flows
    • Import sets
    • Lists
    • Properties
    • Records
    • Roles
    • Script actions
    • Script includes
    • Scripted REST APIs
    • Service level agreements (SLAs)
    • Service portal widgets
    • Tables
    • UI actions
    • UI pages
    • UI policies
    • Workspaces
    Note:
    A limited number of metadata types, such as Metadata Snapshots [sys_metadata_link] and UX Assets [sys_ux_lib_asset], can't be represented as ServiceNow Fluent code and aren't transformed. These metadata types remain as metadata XML files in the metadata directory of your application.

    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.

    The following example includes the definitions of a table, client script, and business rule in the application. The client script uses a script from the client-script.js file. The business rule uses a function from the script.js JavaScript module.
    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,
    })
    The client script referenced from the ClientScript object:
    function onLoad() {
        g_form.addInfoMessage("Table loaded successfully!!")
    }
    The JavaScript module referenced from the BusinessRule object:
    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.

    Figure 1. Application metadata generated from ServiceNow Fluent code
    Application files generated from the example code.
    Tip:
    You can use the following directives in a code comment to help manage your code:
    • @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.