Skip to main content
Version: 4.5.0

Now.include

Now.include() populates a record field with the contents of a file at build time. It's the recommended way to manage scripts, HTML, and CSS in Fluent projects — keeping them as separate files with full IDE support (syntax highlighting, IntelliSense, linting) rather than embedding them as inline strings in .now.ts files.

Syntax

Now.include(filePath: string): string

The file path is relative to the .now.ts file that contains the call.

How it works

  1. At build time: The SDK reads the file and inlines its contents into the XML output field
  2. At transform time (XML → Fluent): The SDK extracts field content into separate files and generates Now.include() calls in the .now.ts output

This enables a round-trip workflow where scripts are always maintained as standalone files.

Supported file types

TypeCommon extensionsUse case
JavaScript.js, .client.js, .server.jsServer scripts, client scripts, business rule scripts
HTML.htmlUI Page HTML, widget templates
CSS/SCSS.css, .scssWidget styles, UI Page styles

Examples

Business Rule with external script

import { BusinessRule } from '@servicenow/sdk/core'

BusinessRule({
$id: Now.ID['validate-on-insert'],
name: 'Validate on Insert',
table: 'incident',
when: 'before',
insert: true,
script: Now.include('../server/validate-on-insert.js'),
})

The script lives in a separate file with full JavaScript IDE support:

// server/validate-on-insert.js
(function executeRule(current, previous) {
if (!current.short_description) {
current.setAbortAction(true);
gs.addErrorMessage('Short description is required');
}
})(current, previous);

UI Page with HTML, client script, and server script

import { UiPage } from '@servicenow/sdk/core'

UiPage({
$id: Now.ID['my-ui-page'],
name: 'my_custom_page',
html: Now.include('../../server/UiPage/my-page.html'),
clientScript: Now.include('../../server/UiPage/my-page.client-script.client.js'),
processingScript: Now.include('../../server/UiPage/my-page.processing-script.server.js'),
})

Service Portal Widget

import { SPWidget } from '@servicenow/sdk/core'

SPWidget({
$id: Now.ID['my-widget'],
name: 'My Custom Widget',
clientScript: Now.include('../../server/SPWidget/my-widget.client.js'),
serverScript: Now.include('../../server/SPWidget/my-widget.server.js'),
htmlTemplate: Now.include('../../server/SPWidget/my-widget.html'),
customCss: Now.include('../../server/SPWidget/my-widget.scss'),
})

Record with HTML content

import { Record } from '@servicenow/sdk/core'

Record({
$id: Now.ID['my-record'],
table: 'x_my_table',
data: {
name: 'My Record',
description_html: Now.include('./html/description.html'),
script: Now.include('../scripts/myScript.js'),
},
})

Inline scripts (alternative)

For very short scripts, you can use inline strings instead of Now.include():

BusinessRule({
$id: Now.ID['simple-rule'],
name: 'Set Priority',
table: 'incident',
when: 'before',
insert: true,
script: `(function executeRule(current, previous) {
current.priority = 1;
})(current, previous);`,
})

Use Now.include() when:

  • The script is more than a few lines
  • You want syntax highlighting and linting
  • Multiple records share the same script
  • The content is HTML or CSS