### Record example for populating demo data Source: https://servicenow.github.io/sdk/llms-full.txt 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. ```APIDOC ## 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. ### Method Record ### Endpoint N/A (SDK Function) ### Parameters #### Request Body - **$id** (string) - Required - Unique identifier for the record. - **table** (string) - Required - The table to create the record in. - **data** (object) - Required - The data for the record. - **number** (string) - Optional - The incident number. - **active** (boolean) - Optional - Whether the incident is active. - **short_description** (string) - Optional - A brief description of the incident. - **description** (string) - Optional - A detailed description of the incident. - **comments** (string) - Optional - Comments related to the incident. - **urgency** (number) - Optional - The urgency level of the incident. - **approval** (string) - Optional - The approval status of the incident. - **notify** (number) - Optional - Notification setting. - **priority** (number) - Optional - The priority level of the incident. - **$meta** (object) - Optional - Metadata for the record. - **installMethod** (string) - Optional - Specifies how the record should be installed (e.g., 'demo'). ### Request Example ```json { "$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" } } } ``` ### Response N/A (SDK Function) ``` -------------------------------- ### Basic CatalogItem Example Source: https://servicenow.github.io/sdk/llms-full.txt Example of creating a catalog item with checkbox variables and pricing details. ```APIDOC ## POST /api/catalog/items (Example) ### Description Creates a catalog item with checkbox variables and pricing. ### Method POST ### Endpoint /api/catalog/items ### Request Body - **$id** (string) - Required - Unique identifier for the catalog item. - **name** (string) - Required - The name of the catalog item. - **shortDescription** (string) - A short description of the catalog item. - **description** (string) - A detailed description of the catalog item. - **flow** (string) - The ID of the workflow that defines how the item request is fulfilled. - **catalogs** (string[]) - An array of catalog IDs where the item should be available. - **variables** (Record) - An object containing the variables for the catalog item. - **premiumSupport** (CheckboxVariable) - Configuration for the 'Premium Support' checkbox variable. - **question** (string) - The question text for the variable. - **order** (number) - The display order of the variable. - **selectionRequired** (boolean) - Whether the checkbox must be selected. - **pricingDetails** (PricingDetail[]) - Pricing details associated with the checkbox selection. - **amount** (number) - The price amount. - **currencyType** (string) - The currency type (e.g., 'USD'). - **field** (string) - The field to which this pricing applies (e.g., 'price_if_checked'). - **rushDelivery** (CheckboxVariable) - Configuration for the 'Rush Delivery' checkbox variable. - **question** (string) - The question text for the variable. - **order** (number) - The display order of the variable. - **selectionRequired** (boolean) - Whether the checkbox must be selected. ### Request Example ```typescript import { CatalogItem, CheckboxVariable } from '@servicenow/sdk/core' export const BasicCatalogItem = CatalogItem({ $id: Now.ID['checkbox_pricing_item'], name: 'Checkbox Pricing Test', shortDescription: 'Test checkbox with pricing', description: 'Catalog item with checkbox variables and pricing details', flow: '30f3d26187e92300e0ef0cf888cb0b91', 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, }), }, }) ``` ### Response #### Success Response (200) - **CatalogItem** (object) - The created catalog item object. #### Response Example ```json { "sys_id": "some_sys_id", "name": "Checkbox Pricing Test", "short_description": "Test checkbox with pricing", "description": "Catalog item with checkbox variables and pricing details", "flow": "30f3d26187e92300e0ef0cf888cb0b91", "catalogs": [ { "link": "/api/now/table/sc_catalog/e0d08b13c3330100c8b837659bba8fb4" } ], "variables": { "premiumSupport": { "question": "Premium Support", "order": 1, "selectionRequired": true, "pricing_details": [ { "amount": 100, "currency_type": "USD", "field": "price_if_checked" } ] }, "rushDelivery": { "question": "Rush Delivery", "order": 2, "selectionRequired": false } } } ``` ``` -------------------------------- ### Service Portal Widget with External Files Example Source: https://servicenow.github.io/sdk/llms-full.txt Example demonstrating how to create a Service Portal widget using external files for client script, server script, HTML template, and CSS. ```APIDOC ## POST /api/now/sp/widget (Example) ### Description This example demonstrates the creation of a Service Portal widget with external script and template files using the ServiceNow SDK. ### Method POST (Implicit, as this is a configuration example for widget creation) ### Endpoint N/A (This is a configuration object, not a direct API endpoint call) ### Request Body Example ```typescript import { SPWidget } from '@servicenow/sdk/core' // Chart.js dependency sys_id (ServiceNow-provided library) const CHARTJS = 'a7a8754347011200ba13a5554ee4905c' SPWidget({ $id: Now.ID['sample-widget'], name: 'Sample Widget', id: 'sample-widget', clientScript: Now.include('../../server/SPWidget/sample-widget.client.js'), serverScript: Now.include('../../server/SPWidget/sample-widget.server.js'), htmlTemplate: Now.include('../../server/SPWidget/sample-widget.html'), customCss: Now.include('../../server/SPWidget/sample-widget.scss'), demoData: { data: { incidents: [99, 59, 80, 81, 56, 55, 40, 0, 5, 21, 11, 30], }, }, hasPreview: true, dependencies: [CHARTJS], }) ``` ### Associated Files **sample-widget.client.js** ```javascript function controller() { this.onClick = () => { console.log('Widget clicked') } } ``` **sample-widget.server.js** ```javascript ;(() => { data.message = 'Hello from the widget server script' })() ``` **sample-widget.html** ```html

Sample Widget

Hello from the widget

``` **sample-widget.scss** ```css .panel { margin: 10px; border-radius: 4px; } .panel-heading { background-color: #f5f5f5; } .panel-body { padding: 15px; } ``` ``` -------------------------------- ### Basic Daily Scheduled Script Example Source: https://servicenow.github.io/sdk/llms-full.txt Example of creating a simple scheduled script that runs daily at a specific time. ```typescript /** * @title Basic Daily Scheduled Script * @description Create a simple scheduled script that runs daily at a specific time */ import { ScheduledScript } from '@servicenow/sdk/core' export const DailyMaintenanceJob = ScheduledScript({ $id: Now.ID['daily_maintenance'], name: 'Daily Maintenance Job', active: true, frequency: 'daily', executionTime: { hours: 2, minutes: 0, seconds: 0 }, script: ` // Daily maintenance script gs.info('Running daily maintenance...'); `, }) ``` -------------------------------- ### Basic AiAgenticWorkflow Example Source: https://servicenow.github.io/sdk/llms-full.txt A minimal AI Agentic Workflow definition requires name, description, and acl. This example demonstrates how to create such a workflow. ```typescript import { AiAgenticWorkflow } from "@servicenow/sdk/core"; /** * @title Basic AiAgenticWorkflow Example * @description A minimal AI Agentic Workflow definition with the required fields: * name, description, and acl. */ export const basicWorkflow = AiAgenticWorkflow({ name: "Basic Support Workflow", description: "A simple agentic workflow that coordinates agents for support tasks", acl: "itil", }); ``` -------------------------------- ### Basic Business Rule Example Source: https://servicenow.github.io/sdk/llms-full.txt Example of creating a business rule that runs after an update on the incident table. ```APIDOC ## Basic Business Rule Example ### Description Creates a business rule that runs after an update on the incident table. ### Method POST (Implicitly, as it configures a business rule) ### Endpoint (Configuration object for BusinessRule) ### Request Body - **$id** (string) - Required - Unique ID for the business rule. - **action** (('update' | 'delete' | 'query' | 'insert')[]) - Required - Specifies 'update' as the triggering action. - **table** (string) - Required - The table the rule applies to ('incident'). - **name** (string) - Required - The name of the business rule ('LogStateChange'). - **order** (number) - Optional - The order of execution (100). - **when** ('before' | 'after' | 'async' | 'display' | 'async_deprecated') - Required - Specifies 'after' for execution timing. - **active** (boolean) - Optional - Enables the business rule (true). ### Request Example ```typescript import { BusinessRule } from '@servicenow/sdk/core' export const LogStateChangeExample = BusinessRule({ $id: 'br0', action: ['update'], table: 'incident', name: 'LogStateChange', order: 100, when: 'after', active: true, }) ``` ### Response (Not applicable for configuration object definition, but would typically be a success confirmation or the created object's ID upon API creation.) ``` -------------------------------- ### Basic ATF Test Example Source: https://servicenow.github.io/sdk/llms-full.txt Create an automated test that verifies server-side logic using ATF steps. This example demonstrates how to initialize a test and log a message. ```typescript /** * @title Basic ATF Test Example * @description Create an automated test that verifies server-side logic using ATF steps */ import { Test } from '@servicenow/sdk/core' export const verifyIncidentCreation = Test( { $id: Now.ID['verify_incident_creation'], name: 'Verify Incident Creation', description: 'Checks that a new incident record can be created with required fields', active: true, failOnServerError: true, }, (atf) => { atf.server.log({ $id: Now.ID['log_start'], log: 'Starting incident creation test', }) } ) ``` -------------------------------- ### Create Minimal Applicability Configuration Source: https://servicenow.github.io/sdk/llms-full.txt A minimal example for creating an applicability configuration with a single role. Import Applicability and Role from '@servicenow/sdk/core'. ```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], }) ``` -------------------------------- ### Basic List Configuration Example Source: https://servicenow.github.io/sdk/llms-full.txt Creates a list layout for CMDB server records with a custom view. Ensure the `Record` and `List` are imported from '@servicenow/sdk/core'. ```typescript /** * @title Basic List Configuration * @description Create a list layout for CMDB server records with a custom view */ import { Record, List } from '@servicenow/sdk/core' const llama_task_view_1 = Record({ table: 'sys_ui_view', $id: Now.ID['llama_task_view_1'], data: { name: 'llama_task_view_1', title: 'llama_task_view_1', }, }) List({ $id: Now.ID['1'], table: 'cmdb_ci_server', view: llama_task_view_1, columns: [ { element: 'name', position: 0 }, { element: 'business_unit', position: 1 }, { element: 'vendor', position: 2 }, { element: 'cpu_type', position: 3 }, ], }) ``` -------------------------------- ### Create a Basic Dashboard with SDK Source: https://servicenow.github.io/sdk/llms-full.txt Example of creating a basic dashboard using the `Dashboard` function from the SDK, including a tab and a widget with specified properties. ```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 ACL Example Source: https://servicenow.github.io/sdk/llms-full.txt Create access control rules for the incident table with role-based permissions. This example shows how to deny read access unless a user has the 'itil' role and then allow read access for users with the 'itil' role. ```APIDOC ## Basic ACL Example ### Description Create access control rules for incident table with role-based permissions. ### Method N/A (SDK Configuration) ### Endpoint N/A (SDK Configuration) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A (SDK Configuration) ### Request Example ```typescript import { Acl, Role } from '@servicenow/sdk/core' export const itilRole = Role({ $id: Now.ID['itil_role'], name: 'itil', }) export const adminRole = Role({ $id: Now.ID['admin_role'], name: 'admin', }) export const incidentDenyUnlessItil = Acl({ $id: Now.ID['incident_deny_unless_itil'], type: 'record', table: 'incident', operation: 'read', decisionType: 'deny', roles: [itilRole], description: 'Deny access to incidents unless user has itil role', active: true, adminOverrides: true, }) export const incidentAllowRead = Acl({ $id: Now.ID['incident_allow_read'], type: 'record', table: 'incident', operation: 'read', decisionType: 'allow', roles: [itilRole], active: true, adminOverrides: true, }) ``` ### Response #### Success Response (200) N/A (SDK Configuration) #### Response Example N/A ``` -------------------------------- ### Create Demo Incident Record Source: https://servicenow.github.io/sdk/llms-full.txt Use the `Record` function to create a demo incident. This record will be installed when the 'Load demo data' option is selected during application installation. ```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 Flow Example Source: https://servicenow.github.io/sdk/llms-full.txt Demonstrates basic usage of the Flow function to create a Flow that fires an event when an incident is created. ```APIDOC ## Basic Flow Example ### Description Demonstrates basic usage of the Flow function to create a Flow that fires an event when an incident is created. ### Method N/A (This is a code example for defining a flow, not an API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## Code Example (TypeScript) ```typescript 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 Angular Provider Example Source: https://servicenow.github.io/sdk/llms-full.txt Creates a minimal Service Portal Angular provider using the SPAngularProvider function. ```APIDOC ## POST /api/now/spangularprovider/basic ### Description Creates a minimal Service Portal Angular provider. ### Method POST ### Endpoint /api/now/spangularprovider/basic ### Request Body ```json { "$id": "Now.ID['my_angular_provider']", "name": "myAngularProvider" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. ### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Create a Dashboard with Visibilities Source: https://servicenow.github.io/sdk/llms-full.txt Example of setting dashboard visibility rules, linking the dashboard to specific UX pages using `Now.ref` for experience references. ```typescript // Source: packages/api/tests/dashboard-plugin/dashboard-plugin.test.ts import { Dashboard } from '@servicenow/sdk/core' export const DashboardWithVisibilitiesExample = Dashboard({ $id: Now.ID['visible-dashboard'], name: 'Visible Dashboard', tabs: [], visibilities: [ { $id: Now.ID['visibility-1'], experience: Now.ref('sys_ux_page_registry', { sys_id: 'abc123def456789' }), }, ], permissions: [], }) ``` -------------------------------- ### Angular Provider with Dependencies Example Source: https://servicenow.github.io/sdk/llms-full.txt Creates an Angular provider that requires other providers, demonstrating dependency management. ```APIDOC ## POST /api/now/spangularprovider/dependencies ### Description Creates an Angular provider that requires other providers, demonstrating dependency management. ### Method POST ### Endpoint /api/now/spangularprovider/dependencies ### Request Body ```json { "$id": "Now.ID['parent-provider-id']", "name": "myAngularProvider", "requires": [ "5f41b53498566648389c9b40286de458", { "$id": "Now.ID['3790304b16c4f94468b2932e79ca7364']", "name": "childProvider", "script": "// child script", "type": "directive" } ] } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. ### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Client-Callable Script Include Source: https://servicenow.github.io/sdk/llms-full.txt Example of creating an AJAX-enabled script include that can be invoked from client-side scripts. ```APIDOC ## ScriptIncludeOptions ### Description An Object containing the properties of the Script Include, specifically configured for client-side accessibility. ### Properties - **$id** (string | number | ExplicitKey) - Required - Unique identifier for the script include. - **name** (string) - Required - The name of the script include. Must match the class, prototype, and type name if defining a class, or the function name for classless script includes. - **active** (boolean) - Optional - Enable or disable the script include. - **apiName** (string) - Optional - The internal name of the Script Include, used for cross-scope calls. Defaults to `{scope}.{name}`. - **clientCallable** (boolean) - Required - Set to `true` to allow the script include to be called from client-side scripts using GlideAjax. - **script** (string) - Required - Defines the server-side script. Must define a single JavaScript class or a global function with a name matching the `name` field. ### Request Example ```typescript ScriptInclude({ $id: Now.ID['ajax-script-include'], name: 'AjaxHelper', active: true, apiName: 'x_myapp.AjaxHelper', clientCallable: true, script: script`var AjaxHelper = Class.create(); AjaxHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, { getUserDisplayName: function() { var userId = this.getParameter('sysparm_user_id'); var gr = new GlideRecord('sys_user'); if (gr.get(userId)) { return gr.getDisplayValue('name'); } return ''; }, type: 'AjaxHelper' });`, }) ``` ``` -------------------------------- ### Basic Flow Example Source: https://servicenow.github.io/sdk/llms-full.txt Creates a flow that fires a custom event and logs a message when an incident is created. ```typescript /** * @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 Record Producer Source: https://servicenow.github.io/sdk/llms-full.txt Example of creating a record producer with checkbox variables and associated pricing. ```APIDOC ## Create Basic Record Producer ### Description Creates a record producer with checkbox variables and pricing details. ### Method CatalogItemRecordProducer ### Endpoint N/A (SDK Function) ### Parameters #### Request Body - **$id** (string) - Required - Unique identifier for the record producer. - **name** (string) - Required - The name of the record producer. - **table** (string) - Required - The table to which the record producer will create records. - **shortDescription** (string) - Required - A brief description of the record producer. - **description** (string) - Optional - A detailed description of the record producer. - **catalogs** (string[]) - Required - An array of catalog IDs where the record producer will be available. - **variables** (object) - Optional - An object containing variable definitions. - **premiumSupport** (CheckboxVariable) - Optional - Definition for a checkbox variable named 'Premium Support'. - **question** (string) - Required - The label for the checkbox. - **order** (number) - Required - The display order of the variable. - **selectionRequired** (boolean) - Required - Whether the checkbox must be selected. - **pricingDetails** (object[]) - Optional - Pricing information for the checkbox. - **amount** (number) - Required - The price amount. - **currencyType** (string) - Required - The currency type (e.g., 'USD'). - **field** (string) - Required - The field to which the price applies. - **rushDelivery** (CheckboxVariable) - Optional - Definition for a checkbox variable named 'Rush Delivery'. - **question** (string) - Required - The label for the checkbox. - **order** (number) - Required - The display order of the variable. - **selectionRequired** (boolean) - Optional - Whether the checkbox must be selected. ### 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, }), }, }) ``` ### Response #### Success Response (200) N/A (SDK function, not an HTTP response) #### Response Example N/A ``` -------------------------------- ### Angular Provider Service Example Source: https://servicenow.github.io/sdk/llms-full.txt Creates an Angular provider of type 'service' with a custom script. ```APIDOC ## POST /api/now/spangularprovider/service ### Description Creates an Angular provider of type 'service' with a custom script. ### Method POST ### Endpoint /api/now/spangularprovider/service ### Request Body ```json { "$id": "Now.ID['my_angular_provider']", "name": "myAngularProvider", "script": "// my provider service", "type": "service" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. ### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Basic Form Example Source: https://servicenow.github.io/sdk/llms-full.txt Creates a simple form with two sections on the default view using a one-column layout. ```APIDOC ## Basic Form Example ### Description Creates a simple form with two sections on the default view using one-column layout. ### Request Example ```typescript import { Form, default_view } from '@servicenow/sdk/core' export const basicForm = Form({ table: 'sn_my_app_task', view: default_view, sections: [ { caption: 'Details', content: [ { layout: 'one-column', elements: [ { field: 'name', type: 'table_field' }, { field: 'description', type: 'table_field' }, ], }, ], }, { caption: 'Assignment', content: [ { layout: 'one-column', elements: [ { field: 'assigned_to', type: 'table_field' }, { field: 'state', type: 'table_field' }, ], }, ], }, ], }) ``` ``` -------------------------------- ### Comprehensive Form Example Source: https://servicenow.github.io/sdk/llms-full.txt Creates a form with two-column layout, annotation, formatter, related list, custom view, and role-based access. ```APIDOC ## Comprehensive Form Example ### Description Creates a form with two-column layout, annotation, formatter, related list, custom view, and role-based access. ### Request Example ```typescript import { Form, Record } from '@servicenow/sdk/core' export const opsView = Record({ $id: Now.ID['ops_view'], table: 'sys_ui_view', data: { name: 'operations', title: 'Operations' }, }) export const comprehensiveForm = Form({ table: 'sn_my_app_task', view: opsView, roles: ['admin', 'itil'], sections: [ { caption: 'Overview', content: [ { layout: 'two-column', leftElements: [ { field: 'name', type: 'table_field' }, { field: 'category', type: 'table_field' }, ], rightElements: [ { field: 'priority', type: 'table_field' }, { field: 'assigned_to', type: 'table_field' }, ], }, { layout: 'one-column', elements: [ { type: 'annotation', annotationId: Now.ID['task_notice'], text: 'Review all fields before saving.', isPlainText: true, annotationType: 'Info_Box_Blue', }, { field: 'description', type: 'table_field' }, ], }, ], }, { caption: 'Activity', content: [ { layout: 'one-column', elements: [ { type: 'formatter', formatterRef: 'Activities_Filtered', }, ], }, ], }, { caption: 'Related Tasks', content: [ { layout: 'one-column', elements: [ { type: 'list', listType: '12M', listRef: 'task_sla.task', }, ], }, ], }, ], }) ``` ``` -------------------------------- ### Record Producer with SelectBox Variables Source: https://servicenow.github.io/sdk/llms-full.txt Example of creating a record producer with selectbox variables, including table-based choices and custom choices with pricing. ```APIDOC ## Create Record Producer with SelectBox Variables ### Description Creates a record producer with selectbox variables, supporting both table-based and custom choices, along with pricing details. ### Method CatalogItemRecordProducer ### Endpoint N/A (SDK Function) ### Parameters #### Request Body - **$id** (string) - Required - Unique identifier for the record producer. - **name** (string) - Required - The name of the record producer. - **table** (string) - Required - The table to which the record producer will create records. - **shortDescription** (string) - Required - A brief description of the record producer. - **description** (string) - Optional - A detailed description of the record producer. - **catalogs** (string[]) - Required - An array of catalog IDs where the record producer will be available. - **variables** (object) - Optional - An object containing variable definitions. - **priorityFromTable** (SelectBoxVariable) - Optional - A selectbox variable sourced from an existing table and field. - **question** (string) - Required - The label for the selectbox. - **order** (number) - Required - The display order of the variable. - **choiceTable** (string) - Required - The table to source choices from. - **choiceField** (string) - Required - The field in the `choiceTable` to use for choices. - **supportLevel** (SelectBoxVariable) - Optional - A selectbox variable with custom choices and pricing. - **question** (string) - Required - The label for the selectbox. - **order** (number) - Required - The display order of the variable. - **choices** (object) - Required - Custom choices for the selectbox. - **basic** (object) - Definition for the 'basic' choice. - **label** (string) - Required - The display label for the choice. - **sequence** (number) - Required - The sequence order of the choice. - **inactive** (boolean) - Required - Whether the choice is inactive. - **pricingDetails** (object[]) - Optional - Pricing information for the choice. - **field** (string) - Required - The field to which the price applies. - **amount** (number) - Required - The price amount. - **currencyType** (string) - Required - The currency type (e.g., 'USD'). - **standard** (object) - Definition for the 'standard' choice. - **label** (string) - Required - The display label for the choice. - **sequence** (number) - Required - The sequence order of the choice. - **inactive** (boolean) - Required - Whether the choice is inactive. - **pricingDetails** (object[]) - Optional - Pricing information for the choice. - **field** (string) - Required - The field to which the price applies. - **amount** (number) - Required - The price amount. - **currencyType** (string) - Required - The currency type (e.g., 'USD'). - **premium** (object) - Definition for the 'premium' choice. - **label** (string) - Required - The display label for the choice. - **sequence** (number) - Required - The sequence order of the choice. - **inactive** (boolean) - Required - Whether the choice is inactive. - **deliveryMethod** (SelectBoxVariable) - Optional - A selectbox variable with simple custom choices. - **question** (string) - Required - The label for the selectbox. - **order** (number) - Required - The display order of the variable. - **choices** (object) - Required - Custom choices for the selectbox. - **email** (object) - Definition for the 'email' choice. - **label** (string) - Required - The display label for the choice. - **sequence** (number) - Required - The sequence order of the choice. - **inactive** (boolean) - Required - Whether the choice is inactive. - **download** (object) - Definition for the 'download' choice. - **label** (string) - Required - The display label for the choice. - **sequence** (number) - Required - The sequence order of the choice. - **inactive** (boolean) - Required - Whether the choice is inactive. - **physical** (object) - Definition for the 'physical' choice. - **label** (string) - Required - The display label for the choice. - **sequence** (number) - Required - The sequence order of the choice. - **inactive** (boolean) - Required - Whether the choice is inactive. ### Request Example ```typescript import { CatalogItemRecordProducer, SelectBoxVariable } from '@servicenow/sdk/core' export const SelectBoxRecordProducer = CatalogItemRecordProducer({ $id: Now.ID['selectbox_test_rp'], name: 'SelectBox Test', table: 'task', shortDescription: 'Test selectbox with choices and pricing', description: 'Record producer with selectbox variables', catalogs: ['e0d08b13c3330100c8b837659bba8fb4'], variables: { priorityFromTable: SelectBoxVariable({ question: 'Priority (From Table)', order: 1, choiceTable: 'task', choiceField: 'priority', }), supportLevel: SelectBoxVariable({ question: 'Support Level', order: 2, choices: { basic: { label: 'Basic Support', sequence: 1, inactive: false, pricingDetails: [ { field: 'misc', amount: 50, currencyType: 'USD', }, ], }, standard: { label: 'Standard Support', sequence: 2, inactive: false, pricingDetails: [ { field: 'misc', amount: 100, currencyType: 'USD', }, { field: 'rec_misc', amount: 25, currencyType: 'USD', }, ], }, premium: { label: 'Premium Support', sequence: 3, inactive: false, }, }, }), deliveryMethod: SelectBoxVariable({ question: 'Delivery Method', order: 3, choices: { email: { label: 'Email', sequence: 1, inactive: false, }, download: { label: 'Download', sequence: 2, inactive: false, }, physical: { label: 'Physical Media', sequence: 3, inactive: false, }, }, }), }, }) ``` ### Response #### Success Response (200) N/A (SDK function, not an HTTP response) #### Response Example N/A ``` -------------------------------- ### Create a Simple REST API with Inline Scripts Source: https://servicenow.github.io/sdk/llms-full.txt Implements a basic REST API with GET and POST routes using inline script templates. ```typescript /** * @title Simple REST API * @description Create a REST API with GET and POST routes using inline scripts */ import { RestApi } from '@servicenow/sdk/core' RestApi({ $id: Now.ID['restapi-hello'], name: 'rest api fluent sample', serviceId: 'restapi_hello', consumes: 'application/json', routes: [ { $id: Now.ID['restapi-hello-get'], name: 'get', method: 'GET', script: script` (function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { response.setBody({ message: 'Hello, World!' }) })(request, response) `, }, { $id: Now.ID['restapi-hello-post'], name: 'post', method: 'POST', script: script` (function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { var reqbody = request.body.dataString; var parser = new global.JSON(); var parsedData = parser.decode(reqbody); response.setBody({ post: parsedData }) })(request, response) `, }, ], }) ``` -------------------------------- ### ScriptOnlyCheck Examples Source: https://servicenow.github.io/sdk/llms-full.txt Examples of creating standalone script checks that do not require table bindings. ```APIDOC ## ScriptOnlyCheck API ### Description Creates instance scan checks that run standalone scripts without table bindings. ### Usage ```typescript 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, }) ``` ### check-admin-overuse.js ```javascript ;(function checkAdminOveruse() { var gr = new GlideAggregate('sys_user_has_role') var adminCount = 0 gr.addQuery('role.name', 'admin') gr.addQuery('user.active', true) gr.addAggregate('COUNT') gr.query() if (gr.next()) { adminCount = parseInt(gr.getAggregate('COUNT')) if (adminCount > 10) { finding.increment() } } })() ``` ``` -------------------------------- ### Basic Email Notification Example Source: https://servicenow.github.io/sdk/llms-full.txt Example of creating an email notification that triggers on incident insertion or update. ```APIDOC ## POST /api/now/table/sys_email_notification ### Description Creates a new email notification configuration. ### Method POST ### Endpoint /api/now/table/sys_email_notification ### Request Body - **table** (string) - Required - The table that this notification applies to. - **name** (string) - Required - Name of the email notification. - **active** (boolean) - Optional, default: true - Whether the notification is active. - **description** (string) - Optional - Description of the email notification. - **triggerConditions** (object) - Optional - Conditions that determine when the notification is triggered. - **onRecordInsert** (boolean) - Optional - Trigger on record insert. - **onRecordUpdate** (boolean) - Optional - Trigger on record update. - **recipientDetails** (object) - Optional - Configuration for who receives the notification. - **recipientFields** (array of strings) - Optional - Fields to determine recipients. - **emailContent** (object) - Optional - Email content and formatting options. - **subject** (string) - Optional - Subject of the email. - **messageHtml** (string) - Optional - HTML message body of the email. ### Request Example ```json { "table": "incident", "name": "Incident Created Notification", "description": "Notify assigned user when an incident is created or updated", "active": true, "triggerConditions": { "onRecordInsert": true, "onRecordUpdate": true }, "recipientDetails": { "recipientFields": ["assigned_to"] }, "emailContent": { "subject": "Incident ${number}: ${short_description}", "messageHtml": "

An incident has been created or updated.

Number: ${number}

Priority: ${priority}

" } } ``` ### Response #### Success Response (201 Created) - **sys_id** (string) - The unique identifier for the created notification. - **number** (string) - The notification number. #### Response Example ```json { "result": { "sys_id": "a1b2c3d4e5f678901234567890abcdef", "number": "NOTIF0010001" } } ``` ```