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
- At build time: The SDK reads the file and inlines its contents into the XML output field
- At transform time (XML → Fluent): The SDK extracts field content into separate files and generates
Now.include()calls in the.now.tsoutput
This enables a round-trip workflow where scripts are always maintained as standalone files.
Supported file types
| Type | Common extensions | Use case |
|---|---|---|
| JavaScript | .js, .client.js, .server.js | Server scripts, client scripts, business rule scripts |
| HTML | .html | UI Page HTML, widget templates |
| CSS/SCSS | .css, .scss | Widget 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