### Example Agent System Prompt for ServiceNow SDK Source: https://servicenow.github.io/sdk This prompt guides AI agents on how to determine the correct API reference to use based on the project's installed SDK version. It involves checking package.json, fetching versions.json, and loading the appropriate llmsFull URL. ```text Before generating any ServiceNow Fluent SDK code: 1. Read the local project's package.json and find the version of @servicenow/sdk in dependencies. 2. Fetch https://servicenow.github.io/sdk/versions.json and find the closest semver match to the installed version. 3. Load the llmsFull URL from that version entry as your API reference. Example: if package.json has "@servicenow/sdk": "4.5.0", fetch versions.json, match "4.5.0", and load its llmsFull value as the API reference before coding. ``` -------------------------------- ### Workspace with List Configuration Example Source: https://servicenow.github.io/sdk/api/workspace An advanced example demonstrating the configuration of a workspace with detailed list settings. ```APIDOC ### Request Example ```javascript // Source: packages/api/tests/workspace-plugin/workspace-plugin.test.ts // Also: examples/workspace/src/fluent/index.now.ts import { Workspace, UxListMenuConfig, Applicability, Role } from '@servicenow/sdk/core' const role1 = Role({ name: 'x_snc_works_7.user', containsRoles: ['canvas_user'], }) const role2 = Role({ name: 'x_snc_works_7.admin', containsRoles: ['canvas_admin'], }) const applicability = Applicability({ $id: Now.ID['workspace_applicability'], name: 'Workspace Audience', roles: [role1, role2], }) const listConfig = UxListMenuConfig({ $id: Now.ID['workspace_list_config'], name: 'Workspace List Config', description: 'List configuration for workspace', categories: [ { $id: Now.ID['incidents_category'], title: 'Incidents', order: 10, lists: [ { $id: Now.ID['incidents_open'], title: 'Open', order: 10, condition: 'active=true^EQ', table: 'incident', columns: 'number,short_description,priority,state', applicabilities: [ { $id: Now.ID['incidents_open_applicability'], active: true, applicability: applicability, }, ], }, ], }, ], }) export const WorkspaceWithListConfigExample = Workspace({ $id: Now.ID['workspace-with-list'], title: "Kevin's Grass 3", path: 'kevins-grass3', landingPath: 'home', active: true, tables: ['incident', 'problem', 'sys_user'], listConfig: listConfig, }) ``` ``` -------------------------------- ### Workspace with Landing Path Example Source: https://servicenow.github.io/sdk/api/workspace An example showing how to configure a workspace with a specific landing path. ```APIDOC ### Request Example ```javascript // Source: packages/api/tests/workspace-plugin/workspace-plugin.test.ts import { Workspace } from '@servicenow/sdk/core' export const WorkspaceWithLandingExample = Workspace({ $id: Now.ID['workspace-landing'], title: 'Test Workspace', path: 'test_workspace', landingPath: 'test_home', active: false, tables: ['incident', 'problem', 'sys_user'], }) ``` ``` -------------------------------- ### Basic Workspace Example Source: https://servicenow.github.io/sdk/api/workspace A simple example demonstrating the creation of a workspace with essential properties. ```APIDOC ### Request Example ```javascript // Source: packages/api/tests/workspace-plugin/workspace-plugin.test.ts import { Workspace } from '@servicenow/sdk/core' export const BasicWorkspaceExample = Workspace({ $id: Now.ID['basic-workspace'], title: 'Test Workspace', path: 'test_workspace', tables: ['incident', 'problem', 'sys_user'], }) ``` ``` -------------------------------- ### Install ServiceNow SDK Source: https://servicenow.github.io/sdk Install the ServiceNow SDK using npm. This command is typically run once at the beginning of a project. ```bash npm install @servicenow/sdk -d ``` -------------------------------- ### Basic Service Portal Example Source: https://servicenow.github.io/sdk/api/service-portal A minimal example demonstrating how to initialize a basic Service Portal using the SDK. This includes essential properties like `$id`, `title`, and `urlSuffix`. ```APIDOC ## POST /api/service-portal/basic ### Description Initializes a basic Service Portal with essential configuration. ### Method POST ### Endpoint `/api/service-portal/basic` ### Request Body ```json { "$id": "Now.ID['test-portal']", "title": "Employee Center", "urlSuffix": "esc" } ``` ### Response #### Success Response (200) Returns a confirmation of the portal initialization. #### Response Example ```json { "status": "success", "message": "Basic portal initialized successfully." } ``` ``` -------------------------------- ### Open Order Guide Source: https://servicenow.github.io/sdk/api/test Opens an Order Guide in the Service Portal. This is the entry point for interacting with an order guide. ```javascript atf.catalog_SP.openOrderGuide ``` -------------------------------- ### Applicability Examples Source: https://servicenow.github.io/sdk/api/workspace/applicability Examples demonstrating various ways to use the Applicability function. ```APIDOC ### applicability-basic ```typescript // Source: examples/workspace/src/fluent/index.now.ts import { Applicability, Role } from '@servicenow/sdk/core' const userRole = Role({ name: 'x_snc_works_7.user', containsRoles: ['canvas_user'], }) const adminRole = Role({ name: 'x_snc_works_7.admin', containsRoles: ['canvas_admin'], }) Applicability({ $id: Now.ID['workspace_applicability'], name: 'Workspace Audience', roles: [userRole, adminRole], }) ``` ### applicability-minimal ```typescript // Source: examples/workspace/src/fluent/index.now.ts import { Applicability, Role } from '@servicenow/sdk/core' const role = Role({ name: 'x_snc_app.user', containsRoles: ['canvas_user'], }) export const MinimalApplicabilityExample = Applicability({ $id: Now.ID['minimal_applicability'], name: 'Minimal Audience', roles: [role], }) ``` ### applicability-role-names ```typescript // Source: packages/core/src/uxf/Applicability.ts (type definition) import { Applicability } from '@servicenow/sdk/core' Applicability({ $id: Now.ID['itil_applicability'], name: 'ITIL Users', description: 'Visible to ITIL and admin roles', roleNames: 'itil,admin', }) ``` ### applicability-with-description ```typescript // Source: packages/core/src/uxf/Applicability.ts (type definition) import { Applicability } from '@servicenow/sdk/core' Applicability({ $id: Now.ID['admin_only_applicability'], name: 'Admin Only Access', description: 'Restricts visibility to admin users', active: true, roles: ['admin'], }) ``` ### applicability-with-role-refs ```typescript // Source: examples/workspace/src/fluent/index.now.ts import { Applicability, Role } from '@servicenow/sdk/core' const role1 = Role({ name: 'x_snc_uxlist.user', containsRoles: ['canvas_user'], }) const role2 = Role({ name: 'x_snc_uxlist.admin', containsRoles: ['canvas_admin'], }) export const ApplicabilityWithRoleRefsExample = Applicability({ $id: Now.ID['list_applicability'], name: 'List Audience', roles: [role1, role2], }) ``` ``` -------------------------------- ### Service Portal with Catalogs Example Source: https://servicenow.github.io/sdk/api/service-portal An example showcasing how to configure a Service Portal with specific catalogs, knowledge bases, and search sources. This demonstrates advanced customization for content integration. ```APIDOC ## POST /api/service-portal/with-catalogs ### Description Initializes a Service Portal with integrated catalogs, knowledge bases, and search sources. ### Method POST ### Endpoint `/api/service-portal/with-catalogs` ### Request Body ```json { "$id": "Now.ID['test-portal-m2m']", "title": "Employee Center", "urlSuffix": "esc", "logo": "a99f9564ff212210a6f3ffffffffff74", "theme": "ee2e485f9c0b5250f877097911a1a148", "homePage": "0987d9aa53331210b8f2ddeeff7b129d", "enableAiSearch": true, "defaultPortal": true, "enableFavorites": true, "taxonomies": [ { "taxonomy": "1f5d5a40c3203010069aec4b7d40dd93", "order": 100, "active": true } ], "knowledgeBases": [ { "knowledgeBase": "kb123", "order": 100, "active": true } ], "catalogs": [ { "catalog": "cat123", "order": 100, "active": true } ], "searchSources": [ { "searchSource": "search123", "order": 100 } ] } ``` ### Response #### Success Response (200) Returns a confirmation of the portal initialization with catalogs. #### Response Example ```json { "status": "success", "message": "Portal with catalogs initialized successfully." } ``` ``` -------------------------------- ### Service Portal with Pages Example Source: https://servicenow.github.io/sdk/api/service-portal This example demonstrates how to configure a Service Portal with custom pages, including the home page, login page, and not found page. It also shows how to set the main menu and theme. ```APIDOC ## POST /api/service-portal/with-pages ### Description Initializes a Service Portal with custom pages, main menu, and theme configurations. ### Method POST ### Endpoint `/api/service-portal/with-pages` ### Request Body ```json { "$id": "Now.ID['employee-center']", "title": "Employee Center", "urlSuffix": "esc", "logo": "a99f9564ff212210a6f3ffffffffff74", "theme": "ee2e485f9c0b5250f877097911a1a148", "mainMenu": "493d01365368301056c1ddeeff7b1207", "homePage": "0987d9aa53331210b8f2ddeeff7b129d", "loginPage": "6995a144cb11120000f8d856634c9c25", "notFoundPage": "3c2c9063cb11020000f8d856634c9c1f", "catalogHomePage": "c221e520b7602300d0ac9277ee11a960", "knowledgeHomePage": "f8b574a0b7202300d0ac9277ee11a91d", "enableAiSearch": true, "defaultPortal": true, "enableFavorites": true } ``` ### Response #### Success Response (200) Returns a confirmation of the portal initialization with custom pages. #### Response Example ```json { "status": "success", "message": "Portal with pages initialized successfully." } ``` ``` -------------------------------- ### Basic Role Creation Source: https://servicenow.github.io/sdk/api/role Example demonstrating how to create a simple application role with a description. ```APIDOC ## Basic Role ### Description Create a simple application role with description ### Code ```javascript /** * @title Basic Role * @description Create a simple application role with description */ import { Role } from '@servicenow/sdk/core' Role({ name: 'x_myapp.activity_admin', description: 'Activity admin role for my application', }) ``` ``` -------------------------------- ### Basic VariableSet Example Source: https://servicenow.github.io/sdk/api/service-catalog/variable-set Example of creating a basic VariableSet with checkbox variables. ```APIDOC ## Example: Basic VariableSet Create a variable set with checkbox variables ```javascript // Source: packages/api/tests/service-catalog-plugin/fluent/variable-set-variables/create/checkbox.now.ts /** * @title Basic VariableSet * @description Create a variable set with checkbox variables */ import { VariableSet, CheckboxVariable } from '@servicenow/sdk/core' export const BasicVariableSet = VariableSet({ $id: Now.ID['checkbox_test_set'], title: 'Checkbox Options', variables: { premiumSupport: CheckboxVariable({ question: 'Premium Support', order: 1, selectionRequired: true, pricingDetails: [ { amount: 100, currencyType: 'USD', field: 'price_if_checked', }, ], }), rushDelivery: CheckboxVariable({ question: 'Rush Delivery', order: 2, selectionRequired: false, }), }, }) ``` ``` -------------------------------- ### Basic Dashboard Implementation Source: https://servicenow.github.io/sdk/api/workspace/dashboard A minimal dashboard configuration example. ```typescript // Source: packages/api/tests/dashboard-plugin/dashboard-plugin.test.ts import { Dashboard } from '@servicenow/sdk/core' export const BasicDashboardExample = Dashboard({ $id: Now.ID['basic-dashboard'], name: 'Test Dashboard', tabs: [ { $id: Now.ID['overview-tab'], name: 'Overview', widgets: [ { $id: Now.ID['widget-1'], component: '23051643b7e03010097cb81cde11a910', componentProps: { selectedElements: [], chartVariation: 'stacked', }, height: 12, width: 12, position: { x: 0, y: 0 }, }, ], }, ], visibilities: [], permissions: [], }) ``` -------------------------------- ### Basic Column Type Check Examples Source: https://servicenow.github.io/sdk/api/instance-scan/column-type-check Examples demonstrating the creation of security-focused scan checks for script and HTML column types. ```javascript /** * @title Basic Column Type Check * @description Create an instance scan check that validates script columns for common security issues */ import { ColumnTypeCheck } from '@servicenow/sdk/core' export const scriptColumnSecurityCheck = ColumnTypeCheck({ $id: Now.ID['script-column-security'], name: 'Script Column Security Validator', active: true, category: 'security', priority: '2', shortDescription: 'Scans script columns for hardcoded credentials and injection vulnerabilities', columnType: 'script', description: 'Inspects all script-type columns across the instance for common security anti-patterns including hardcoded passwords, SQL injection vectors, and unsafe eval usage.', resolutionDetails: 'Remove hardcoded credentials and use system properties or credential records instead. Replace dynamic queries with parameterized alternatives.', scoreMin: 0, scoreMax: 100, scoreScale: 1, }) export const htmlColumnXssCheck = ColumnTypeCheck({ $id: Now.ID['html-column-xss'], name: 'HTML Column XSS Scanner', active: true, category: 'security', priority: '1', shortDescription: 'Detects potential cross-site scripting vulnerabilities in HTML columns', columnType: 'html', }) ``` -------------------------------- ### Basic Angular Provider Example Source: https://servicenow.github.io/sdk/api/service-portal/sp-angular-provider Create a minimal Service Portal Angular provider. ```APIDOC ## Basic Angular Provider ### Description Create a minimal Service Portal Angular provider ### Request Example ```javascript /** * @title Basic Angular Provider * @description Create a minimal Service Portal Angular provider */ import { SPAngularProvider } from '@servicenow/sdk/core' SPAngularProvider({ $id: Now.ID['my_angular_provider'], name: 'myAngularProvider', }) ``` ``` -------------------------------- ### Initialize ApprovalRulesColumn Source: https://servicenow.github.io/sdk/api/table/columns/approval-rules-column Examples of initializing approval rules columns with basic and mandatory configurations. ```javascript const approvalRules = ApprovalRulesColumn({ label: 'Approval Rules', }) const workflowRules = ApprovalRulesColumn({ label: 'Workflow Rules', mandatory: true, }) ``` -------------------------------- ### Create TableCheck configurations Source: https://servicenow.github.io/sdk/api/instance-scan/table-check Examples demonstrating condition-only, script-only, and combined condition-and-script modes for table scanning. ```javascript // Condition-based check TableCheck({ $id: Now.ID['check-inactive-users'], name: 'Inactive Users with Roles', active: true, category: 'security', priority: '2', shortDescription: 'Finds inactive users that still have active roles', table: 'sys_user', conditions: 'active=false^roles!=', }) // Advanced script-based check TableCheck({ $id: Now.ID['check-large-attachments'], name: 'Large Attachment Detector', active: true, category: 'performance', priority: '3', shortDescription: 'Identifies records with oversized attachments', table: 'sys_attachment', advanced: true, script: Now.include('./check-large-attachments.js'), }) // Combined conditions and script check TableCheck({ $id: Now.ID['check-stale-incidents'], name: 'Stale Incident Detector', active: true, category: 'manageability', priority: '2', shortDescription: 'Finds incidents that are open and stale', table: 'incident', advanced: true, conditions: 'state!=6^state!=7', script: Now.include('./check-stale-incidents.js'), }) ``` -------------------------------- ### Submit Order Guide Source: https://servicenow.github.io/sdk/api/test Submits an Order Guide in the Service Portal, similar to clicking 'Order Now' for a standard catalog item. ```javascript atf.catalog_SP.submitOrderGuide ``` -------------------------------- ### Initialize MultiLineTextColumn Source: https://servicenow.github.io/sdk/api/table/columns/multi-line-text-column Examples of initializing a MultiLineTextColumn with different configurations such as maxLength and default values. ```javascript const description = MultiLineTextColumn({ label: 'Description', maxLength: 1000, }) const notes = MultiLineTextColumn({ label: 'Notes', default: 'Enter notes here...', }) ``` -------------------------------- ### MultiLineTextColumn Usage Source: https://servicenow.github.io/sdk/api/table/columns/multi-line-text-column Example of how to instantiate and configure a MultiLineTextColumn. ```APIDOC ## Function: MultiLineTextColumn(config) A Column for a multiple line small text area field. Allows multi-line text input without the complexity of rich text editing. ### Usage ```javascript const description = MultiLineTextColumn({ label: 'Description', maxLength: 1000, }) const notes = MultiLineTextColumn({ label: 'Notes', default: 'Enter notes here...', }) ``` ### Parameters #### config `C & Column` an object that can include all base `Column` properties * **maxLength**? - maximum number of characters allowed in this field ### Properties * **active** (optional): `boolean` Indicates whether to display the field in list and forms * **array** (optional): `boolean` Creates another table to store the info that will be captured by this field * **attributes** (optional): `Record` Pairs of any supported dictionary attributes (sys_schema_attribute) * **audit** (optional): `boolean` Indicates whether to track the creation, update, and deletion of all records in the table. * **default** (optional): `Default | string` Default value of the field when creating a record * **dependent** (optional): `string` limit the values available to select based on the value of the dependent field * **elementReference** (optional): `boolean` Indicates if the value of this field connotes the "element type" * **functionDefinition** (optional): `string` Definition of a function that the field performs * **help** (optional): `string` Help information for the field * **hint** (optional): `string` Describes field in more verbose form * **label** (optional): `string | Documentation[]` Unique label for the column that appears on list headers and form fields * **mandatory** (optional): `boolean` Indicates whether the field must contain a value to save a record * **maxLength** (optional): `number | string` Maximum length of the field value * **plural** (optional): `string` Plural form of the field name * **primary** (optional): `boolean` Indicates the primary key for a table * **readOnly** (optional): `boolean` Indicates whether you can edit the field value * **readOnlyOption** (optional): `readOnlyOptionType` Specifies the read-only behavior for the field * **spellCheck** (optional): `boolean` Enables spell check for this field * **tableReference** (optional): `boolean` Indicates if the value of this field is a reference to another table in the schema * **textIndex** (optional): `boolean` Enables a natural language search on this field * **unique** (optional): `boolean` Creates a unique index on this field * **widget** (optional): `string` Style for the element type such as "radio" * **xmlView** (optional): `boolean` Displays the field value as XML ### See * https://docs.servicenow.com/csh?topicname=table-api-now-ts.html&version=latest ``` -------------------------------- ### JavaScript Includes Example Source: https://servicenow.github.io/sdk/api/service-portal/sp-widget-dependency Create JS includes from external URLs or sys_ui_script records. ```APIDOC ## JavaScript Includes ### Description Create JS includes from external URLs or sys_ui_script records. ### Request Example ```javascript import { JsInclude } from '@servicenow/sdk/core' // JS Include from URL JsInclude({ $id: Now.ID['chartjs-include'], name: 'Chart.js', url: 'https://cdn.jsdelivr.net/npm/chart.js', }) // JS Include from sys_ui_script JsInclude({ $id: Now.ID['ui-script-include'], name: 'Custom UI Script', sysUiScript: '5f41b53498566648389c9b40286de458', }) ``` ``` -------------------------------- ### Multiple Access Levels Source: https://servicenow.github.io/sdk/api/role Example showing the creation of viewer, editor, and admin roles for tiered permissions. ```APIDOC ## Multiple Access Levels ### Description Create viewer, editor, and admin roles for tiered permissions ### Code ```javascript /** * @title Multiple Access Levels * @description Create viewer, editor, and admin roles for tiered permissions */ import { Role } from '@servicenow/sdk/core' export const viewer = Role({ name: 'x_myapp.viewer', description: 'Read-only access to application data', }) export const editor = Role({ name: 'x_myapp.editor', description: 'Can edit records in the application', }) export const admin = Role({ name: 'x_myapp.admin', description: 'Full administrative access', }) ``` ``` -------------------------------- ### Widget Dependency with JS and CSS Example Source: https://servicenow.github.io/sdk/api/service-portal/sp-widget-dependency Create a widget dependency that bundles JavaScript and CSS includes. ```APIDOC ## Widget Dependency with JS and CSS ### Description Create a widget dependency that bundles JavaScript and CSS includes. ### Request Example ```javascript import { SPWidgetDependency, JsInclude, CssInclude } from '@servicenow/sdk/core' const myJsInclude = JsInclude({ $id: Now.ID['my-js-include'], name: 'My JS Include', url: 'https://cdn.example.com/script.js', }) const myCssInclude = CssInclude({ $id: Now.ID['my-css-include'], name: 'My CSS Include', url: 'https://cdn.example.com/style.css', }) SPWidgetDependency({ $id: Now.ID['my-dependency'], name: 'My Widget Dependency', angularModuleName: 'myModule', jsIncludes: [{ order: 100, include: myJsInclude }], cssIncludes: [{ order: 100, include: myCssInclude }], }) ``` ``` -------------------------------- ### CSS Includes Example Source: https://servicenow.github.io/sdk/api/service-portal/sp-widget-dependency Create CSS includes from external URLs or sp_css records with RTL support. ```APIDOC ## CSS Includes ### Description Create CSS includes from external URLs or sp_css records with RTL support. ### Request Example ```javascript import { CssInclude } from '@servicenow/sdk/core' // CSS Include from URL CssInclude({ $id: Now.ID['bootstrap-css'], name: 'Bootstrap CSS', url: 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css', rtlCssUrl: 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css', }) // CSS Include from sp_css with lazy loading CssInclude({ $id: Now.ID['custom-css'], name: 'Custom Portal CSS', spCss: 'ccfbb128f13494f68c570b646ba5d335', lazyLoad: true, }) ``` ``` -------------------------------- ### Navigate Within Order Guide Source: https://servicenow.github.io/sdk/api/test Allows navigation between different sections or steps within an Order Guide in the Service Portal. Use this to control the flow of the guide. ```javascript atf.catalog_SP.navigatewithinOrderGuide ``` -------------------------------- ### Validate Order Guide Item Source: https://servicenow.github.io/sdk/api/test Validates specific items included within an Order Guide in the Service Portal. Use this to ensure correct items are part of the guide. ```javascript atf.catalog_SP.validateOrderGuideItem ``` -------------------------------- ### Multi-Row VariableSet Example Source: https://servicenow.github.io/sdk/api/service-catalog/variable-set Example of creating a multi-row VariableSet with checkbox variables. ```APIDOC ## Example: Multi-Row VariableSet Create a multi-row variable set with checkbox variables ```javascript // Source: packages/api/tests/service-catalog-plugin/fluent/variable-set-variables/create/checkbox.now.ts /** * @title Multi-Row VariableSet * @description Create a multi-row variable set with checkbox variables */ import { VariableSet, CheckboxVariable } from '@servicenow/sdk/core' export const MultiRowVariableSet = VariableSet({ $id: Now.ID['multi_row_checkbox_set'], title: 'Multi-Row Checkbox Options', type: 'multiRow', variables: { premiumSupport: CheckboxVariable({ question: 'Premium Support', order: 1, selectionRequired: true, pricingDetails: [ { amount: 100, currencyType: 'USD', field: 'price_if_checked', }, { amount: 50, currencyType: 'GBP', field: 'rec_price_if_checked', }, ], }), extendedWarranty: CheckboxVariable({ question: 'Extended Warranty', order: 2, pricingDetails: [ { amount: 200, currencyType: 'EUR', field: 'price_if_checked', }, ], }), rushDelivery: CheckboxVariable({ question: 'Rush Delivery', order: 3, selectionRequired: false, }), }, }) ``` ``` -------------------------------- ### Populate demo data using Record Source: https://servicenow.github.io/sdk/api/record Use the $meta property with installMethod set to 'demo' to include records during application installation when demo data is selected. ```typescript /** * @title Record example for populating demo data * @description For defining demo data in your application, some APIs expose the `$meta: { installMethod }` property * which allows you to specify a record that should be created during installation of your application. * This example shows how to use the `Record` function to create a record in the `incident` table, and * install the record when the "Load demo data" option is selected during installation */ import { Record } from '@servicenow/sdk/core' Record({ $id: Now.ID['incident-1'], table: 'incident', data: { number: 'INC0010001', active: true, short_description: 'This is a sample incident', description: 'This is a sample incident description', comments: 'This is a sample comment', urgency: 1, approval: 'not requested', notify: 1, priority: 3, $meta: { installMethod: 'demo' } }, }) ``` -------------------------------- ### Basic Record Producer Example Source: https://servicenow.github.io/sdk/api/service-catalog/catalog-item-record-producer Demonstrates how to create a record producer with checkbox variables and pricing using the ServiceNow SDK. ```APIDOC ## Basic Record Producer Example ### Description Create a record producer with checkbox variables and pricing. ### Request Example ```typescript import { CatalogItemRecordProducer, CheckboxVariable } from '@servicenow/sdk/core' export const BasicRecordProducer = CatalogItemRecordProducer({ $id: Now.ID['checkbox_pricing_rp'], name: 'Checkbox Pricing Test', table: 'task', shortDescription: 'Test checkbox with pricing', description: 'Record producer with checkbox variables and pricing details', catalogs: ['e0d08b13c3330100c8b837659bba8fb4'], variables: { premiumSupport: CheckboxVariable({ question: 'Premium Support', order: 1, selectionRequired: true, pricingDetails: [ { amount: 100, currencyType: 'USD', field: 'price_if_checked', }, ], }), rushDelivery: CheckboxVariable({ question: 'Rush Delivery', order: 2, selectionRequired: false, }), }, }) ``` ``` -------------------------------- ### Basic UxListMenuConfig Example Source: https://servicenow.github.io/sdk/api/workspace/ux-list-menu-config Demonstrates a basic configuration for a list menu, including a single category with one list item. Ensure all required properties like $id and name are provided. ```typescript import { UxListMenuConfig } from '@servicenow/sdk/core' export const BasicListMenuConfigExample = UxListMenuConfig({ $id: Now.ID['basic-config'], name: 'Test List Menu Config', description: 'Test description', active: true, categories: [ { $id: Now.ID['category-1'], title: 'Category 1', order: 100, description: 'Category description', lists: [ { $id: Now.ID['incidents-list'], table: 'incident', title: 'Incidents', active: true, order: 100, columns: 'number,short_description,priority', condition: 'active=true', }, ], }, ], }) ``` -------------------------------- ### Review Order Guide Summary Source: https://servicenow.github.io/sdk/api/test Displays or reviews the summary of an Order Guide in the Service Portal. Use this to check the overall order before submission. ```javascript atf.catalog_SP.reviewOrderGuideSummary ``` -------------------------------- ### Review Item in Order Guide Source: https://servicenow.github.io/sdk/api/test Allows reviewing individual items within an Order Guide in the Service Portal and deciding whether to include them in the order. ```javascript atf.catalog_SP.reviewIteminOrderGuide ``` -------------------------------- ### Add Order Guide to Shopping Cart Source: https://servicenow.github.io/sdk/api/test Adds an entire order guide to the shopping cart in the Service Portal. This is distinct from adding individual catalog items. ```javascript atf.catalog_SP.addOrderGuidetoShoppingCart ``` -------------------------------- ### Create a basic Service Portal page Source: https://servicenow.github.io/sdk/api/service-portal/sp-page Demonstrates the minimal configuration required to define a new Service Portal page. ```typescript // Source: packages/api/tests/service-portal/page-plugin.test.ts import { SPPage } from '@servicenow/sdk/core' export const BasicPageExample = SPPage({ title: 'My Simple Page', pageId: 'simple_page', }) ``` -------------------------------- ### Configure LLM Prompt Providers Source: https://servicenow.github.io/sdk/api/now-assist-skill-config Sets up multiple prompt versions for the Now LLM Service, including model selection, temperature, and token limits. ```javascript { providers: [ { // Primary provider: Now LLM Service provider: 'Now LLM Service', prompts: [ { name: 'HR Resolution', versions: [ // Version 1 — draft (initial) { $id: Now.ID['prompt_hr_v1'], version: 1, model: 'llm_generic_small_v2', temperature: 0.2, maxTokens: 2048, prompt: (p) => `You are an HR case resolution assistant.\n\nUser Query: ${p.input['case query']}\nCase Details: ${p.tool.FetchCaseDetails.output}\nPolicy Search Results: ${p.tool.SearchPolicies.response}\nCompliance Status: ${p.tool.ComplianceCheck.Output}\n\nProvide:\n1. A clear recommendation\n2. Referenced policy sections\n3. Confidence score (0-100)`, promptState: 'draft', }, // Version 2 — published (improved) { $id: Now.ID['prompt_hr_v2'], version: 2, model: 'llm_generic_small_v2', temperature: 0.15, maxTokens: 4096, prompt: (p) => `You are an expert HR case resolution assistant with deep knowledge of company policies.\n\n## Context\nUser Query: ${p.input['case query']}\nCase Record: ${p.tool.FetchCaseDetails.output}\nRelated Cases: ${p.input['related case ids']}\n\n## Research\nPolicy Search: ${p.tool.SearchPolicies.response}\nCompliance Check: ${p.tool.ComplianceCheck.Output}\nAction Classification: ${p.tool.ClassifyAction.output}\n\n## Instructions\n1. Analyze the case against company HR policies\n2. Provide a specific, actionable recommendation\n3. List all referenced policy sections as JSON array\n4. Rate your confidence (0-100) based on policy match quality\n\nRespond in structured JSON format.`, promptState: 'published', }, ], }, ], defaultPrompt: 'HR Resolution', defaultPromptVersion: 2, }, { // Fallback provider: Azure OpenAI provider: 'Azure OpenAI', }, ``` -------------------------------- ### Basic Linter Check Example Source: https://servicenow.github.io/sdk/api/instance-scan/linter-check Example of creating instance scan linter checks to enforce coding standards, including deprecated API usage and GlideRecord calls in client scripts. ```APIDOC ## Examples ### Basic Linter Check Create instance scan linter checks that enforce coding standards ```javascript /** * @title Basic Linter Check * @description Create instance scan linter checks that enforce coding standards */ import { LinterCheck } from '@servicenow/sdk/core' export const deprecatedApiCheck = LinterCheck({ $id: Now.ID['lint-deprecated-api'], name: 'Deprecated API Usage', active: true, category: 'upgradability', priority: '3', shortDescription: 'Flags usage of deprecated GlideRecord and GlideSystem APIs', description: 'Scans server-side scripts for calls to deprecated APIs that may be removed in future platform releases.', resolutionDetails: 'Replace deprecated API calls with their recommended alternatives as documented in the ServiceNow API reference.', documentationUrl: 'https://docs.servicenow.com', }) export const performanceLintCheck = LinterCheck({ $id: Now.ID['lint-performance'], name: 'GlideRecord in Client Scripts', active: true, category: 'performance', priority: '2', shortDescription: 'Detects synchronous GlideRecord calls in client-side scripts', }) ``` ``` -------------------------------- ### Examples of Now.attach() Usage Source: https://servicenow.github.io/sdk/guides/now-attach Illustrates how to use Now.attach() in various scenarios, such as adding a logo to a portal, reusing images, and sharing images across multiple records. ```APIDOC ### Portal with a logo ```typescript import { Record } from '@servicenow/sdk/core' Record({ $id: Now.ID['my-portal'], table: 'sp_portal', data: { title: 'My Portal', icon: Now.attach('../../assets/portal-icon.png'), }, }) ``` ### Reusing the same image across multiple fields Store the attachment in a variable to avoid reading and compressing the file multiple times: ```typescript import { Record } from '@servicenow/sdk/core' const logo = Now.attach('../../assets/company-logo.jpg') Record({ $id: Now.ID['portal-a'], table: 'sp_portal', data: { title: 'Portal A', icon: logo, logo: logo, }, }) ``` ### Sharing an image across multiple records ```typescript import { Record } from '@servicenow/sdk/core' const icon = Now.attach('../../assets/app-icon.png') Record({ $id: Now.ID['portal-one'], table: 'sp_portal', data: { title: 'Portal One', icon: icon, }, }) Record({ $id: Now.ID['portal-two'], table: 'sp_portal', data: { title: 'Portal Two', icon: icon, }, }) ``` ``` -------------------------------- ### Basic Flow Example Source: https://servicenow.github.io/sdk/api/flow Demonstrates basic usage of the Flow function to create a Flow that fires an event when an incident is created. ```javascript /** * @title Basic Flow Example * @description Demonstrates basic usage of the Flow function to create a Flow that fires an event when an incident is created. */ import { action, Flow, wfa, trigger } from '@servicenow/sdk/automation' export const testFireEvent = Flow( { $id: Now.ID['test_fire_event_flow'], name: 'Test Fire Event', description: 'Tests the fireEvent core action', }, wfa.trigger( trigger.record.created, { $id: Now.ID['test_fire_event_trigger'] }, { table: 'incident', condition: 'active=true', run_flow_in: 'background', } ), (params) => { wfa.action( action.core.fireEvent, { $id: Now.ID['test_fire_event_action'] }, { event_name: 'custom.incident.created', table: 'incident', record: wfa.dataPill(params.trigger.current.sys_id, 'reference'), parm1: 'Test parameter 1', parm2: 'Test parameter 2', } ) wfa.action( action.core.log, { $id: Now.ID['test_fire_event_log'] }, { log_level: 'info', log_message: 'no output', } ) } ) ``` -------------------------------- ### Basic Script Only Check Example Source: https://servicenow.github.io/sdk/api/instance-scan/script-only-check This example demonstrates creating instance scan checks that run standalone scripts without table bindings. It includes checks for admin role overuse and orphaned update set records. ```typescript /** * @title Basic Script Only Check * @description Create instance scan checks that run standalone scripts without table bindings */ import { ScriptOnlyCheck } from '@servicenow/sdk/core' export const adminRoleOveruseCheck = ScriptOnlyCheck({ $id: Now.ID['check-admin-overuse'], name: 'Admin Role Overuse', active: true, category: 'security', priority: '1', shortDescription: 'Detects excessive admin role assignments across user accounts', script: Now.include('./check-admin-overuse.js'), description: 'Queries sys_user_has_role to identify accounts with admin privileges and flags instances where more than 5% of active users hold the admin role.', resolutionDetails: 'Review admin role assignments and replace with more granular roles where possible.', }) export const orphanedRecordCheck = ScriptOnlyCheck({ $id: Now.ID['check-orphaned-records'], name: 'Orphaned Update Set Records', active: true, category: 'manageability', priority: '4', shortDescription: 'Finds update set records referencing deleted metadata', scoreMin: 0, scoreMax: 50, scoreScale: 2, }) ``` -------------------------------- ### Create Applicability with Description and Active Flag Source: https://servicenow.github.io/sdk/api/workspace/applicability Sets up an applicability configuration that includes a description and explicitly sets the active state to true. Use this to provide context and ensure the rule is immediately active. ```typescript import { Applicability } from '@servicenow/sdk/core' Applicability({ $id: Now.ID['admin_only_applicability'], name: 'Admin Only Access', description: 'Restricts visibility to admin users', active: true, roles: ['admin'], }) ``` -------------------------------- ### Function: GuidColumn(config) Source: https://servicenow.github.io/sdk/api/table/columns/guid-column Defines a GUID column configuration for a table schema. ```APIDOC ## Function: GuidColumn(config) ### Description A Column for a GUID (Globally Unique Identifier) type field. ### Parameters #### config (GuidColumnType) - **active** (boolean) - Optional - Indicates whether to display the field in list and forms - **array** (boolean) - Optional - Creates another table to store the info that will be captured by this field - **attributes** (Record) - Optional - Pairs of any supported dictionary attributes (sys_schema_attribute) - **audit** (boolean) - Optional - Indicates whether to track the creation, update, and deletion of all records in the table - **default** (Default | string) - Optional - Default value of the field when creating a record - **dependent** (string) - Optional - Limit the values available to select based on the value of the dependent field - **elementReference** (boolean) - Optional - Indicates if the value of this field connotes the "element type" - **functionDefinition** (string) - Optional - Definition of a function that the field performs - **help** (string) - Optional - Help information for the field - **hint** (string) - Optional - Describes field in more verbose form - **label** (string | Documentation[]) - Optional - Unique label for the column that appears on list headers and form fields - **mandatory** (boolean) - Optional - Indicates whether the field must contain a value to save a record - **maxLength** (number | string) - Optional - Maximum length of the field value - **plural** (string) - Optional - Plural form of the field name - **primary** (boolean) - Optional - Indicates the primary key for a table - **readOnly** (boolean) - Optional - Indicates whether you can edit the field value - **readOnlyOption** (readOnlyOptionType) - Optional - Specifies the read-only behavior for the field - **spellCheck** (boolean) - Optional - Enables spell check for this field - **tableReference** (boolean) - Optional - Indicates if the value of this field is a reference to another table in the schema - **textIndex** (boolean) - Optional - Enables a natural language search on this field - **unique** (boolean) - Optional - Creates a unique index on this field - **widget** (string) - Optional - Style for the element type such as "radio" - **xmlView** (boolean) - Optional - Displays the field value as XML ``` -------------------------------- ### SlushBucketColumn Usage Source: https://servicenow.github.io/sdk/api/table/columns/slush-bucket-column Demonstrates how to instantiate the SlushBucketColumn function with basic and advanced configurations. ```APIDOC ## SlushBucketColumn(config) A Column for a slush bucket field. Provides a dual-list selection interface for moving items between available and selected lists. ### Usage ```javascript const selectedItems = SlushBucketColumn({ label: 'Selected Items', }) // Using script method const assignedRoles = SlushBucketColumn({ label: 'Assigned Roles', script: 'getRoles()', mandatory: true, }) ``` ### Parameters #### config `object` An object that can include all base `Column` properties **Properties:** * **script** (optional): `string` Script method to populate the slush bucket options. Example: 'getMethod()' - a server-side script that returns available options ``` -------------------------------- ### Define a TimeColumn Source: https://servicenow.github.io/sdk/api/table/columns/time-column Examples of initializing a TimeColumn with different default value formats. ```javascript const startTime = TimeColumn({ label: 'Start Time', default: time({ hours: 9, minutes: 0, seconds: 0 }), }) const endTime = TimeColumn({ label: 'End Time', default: '1970-01-01 17:30:00', }) ``` -------------------------------- ### Create UI Policy with Scripts Source: https://servicenow.github.io/sdk/api/ui-policy Use this example to create a UI policy with condition-based scripts that execute when the condition is true or false. It also includes advanced options like global application, reverseIfFalse, and isolateScript. ```typescript /** * @title UI Policy with Scripts * @description Create a UI policy with condition-based scripts and advanced options */ import { UiPolicy } from '@servicenow/sdk/core' UiPolicy({ $id: Now.ID['policy_with_scripts'], table: 'incident', shortDescription: 'Policy with Scripts', runScripts: true, uiType: 'desktop', scriptTrue: 'function onCondition() { g_form.addErrorMessage("Error"); }', scriptFalse: 'function onCondition() { g_form.clearMessages(); }', conditions: 'state=1', global: true, reverseIfFalse: true, isolateScript: true, }) ``` -------------------------------- ### Initialize DayOfWeekColumn Source: https://servicenow.github.io/sdk/api/table/columns/day-of-week-column Examples of initializing DayOfWeekColumn with different labels and default values. ```javascript const dayOfWeek = DayOfWeekColumn({ label: 'Day of Week', default: 1, // Monday }) const meetingDay = DayOfWeekColumn({ label: 'Meeting Day', default: 5, // Friday }) ```