Service Catalog API - ServiceNow Fluent
The Service Catalog API defines catalog items [sc_cat_item], record producers [sc_cat_item_producer], and related aspects of service catalogs.
Note: For the latest ServiceNow Fluent API documentation and examples, see the ServiceNow Fluent API reference and ServiceNow SDK examples repository on GitHub.
For general information about service catalogs, see Service Catalog.
Parent Topic:ServiceNow Fluent API reference
Related topics
CatalogItem object
Create a catalog item [sc_cat_item] that users can request from a service catalog.
A catalog item must reference a flow, workflow, or execution plan that defines how the item request is fulfilled.
| Name | Type | Description |
|---|---|---|
| $id | String or Number | Required. A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys\_id. For more information, see ServiceNow Fluent language constructs.Format: `Now.ID['String' or Number]` |
| name | String | Required. A name for the item that appears in the catalog. |
| active | Boolean | Flag that indicates whether the item is active and available to be ordered.Default: true |
| availability | String | The type of device on which the item displays.Valid values: - desktopOnly: The item displays only on desktop devices. - mobileOnly: The item displays only on mobile devices. - both: The item displays on both desktop and mobile devices. Default: desktopOnly |
| checkedOut | Boolean | Flag that indicates whether the item is checked out for editing.Default: false |
| description | String | A detailed description of the item that displays in the catalog when a user selects the item or the associated Preview link.You can embed videos, images, links to internal knowledge base (KB) articles, and links to external sources of information and instruction documentation. |
| meta | Array | A list of metadata tags used to aid in searches related to the item.Note: The meta property is used only for Zing text indexing and search engine and not for AI Search. |
| model | Reference or String | The variable identifier or sys\_id of a product model \[cmdb\_model\] associated with the item. To define a product model, use the Record API - ServiceNow Fluent. |
| order | Number | The order in which the item appears within its category.Default: 0 |
| owner | Reference or String | The variable identifier or sys\_id of a user \[sys\_user\] who owns the item and has edit access to it. To define a user, use the Record API - ServiceNow Fluent. |
| roles | Array | A list of variable identifiers of Role objects or sys\_ids of roles \[sys\_user\_role\] that can access the item. For more information, see Role API - ServiceNow Fluent. |
| shortDescription | String | A short description of the item that appears on the catalog home page, search results, and the title bar of the order form. |
| showVariableHelpOnLoad | Boolean | Flag that indicates whether the item displays variable help text by default.Default: false |
| startClosed | Boolean | Flag that indicates whether to start the item in a collapsed state.Default: false |
| state | String | The publication state of the item, such as draft or published. |
| variables | Object | The variable definitions for the item that provide options for requesting it. Each variable type has a specific function. For example: |
| version | Number | A version of the item.Default: 1 |
| image | String | Deprecated. An image for the item. |
| icon | String | An image file that displays as an icon beside the item name in the catalog.Use a 27x27 pixel image. If no image is uploaded, the default icon appears. |
| picture | String | An image file to display as a picture of the item. |
| mobilePicture | String | An image to display as a picture of the item on mobile devices.This property applies only if the value of the mobilePictureType is `mobilePicture`. |
| mobilePictureType | String | The type of picture to display for the item on mobile devices.Valid values: - desktopPicture: Use the image from the picture property. - mobilePicture: Use the image from the mobilePicture property. - noPicture: The item doesn't display a picture on mobile devices. Default: desktopPicture |
| hideAddToCart | Boolean | Flag that indicates whether to hide the Add to Cart button.Default: false |
| hideAddToWishList | Boolean | Flag that indicates whether to hide the Add to Wishlist button.Default: false |
| hideDeliveryTime | Boolean | Flag that indicates whether to hide the delivery time.Default: false |
| hideQuantitySelector | Boolean | Flag that indicates whether to hide the Quantity field.Default: false |
| hideSaveAsDraft | Boolean | Flag that indicates whether to hide the Save as Draft button.Default: false |
| hideSP | Boolean | Flag that indicates whether to hide an item on Service Portal.Default: false |
| mandatoryAttachment | Boolean | Flag that indicates whether to require adding an attachment to submit a request.Default: false |
| hideAttachment | Boolean | Flag that indicates whether to hide the attachment section and not support adding attachments.Default: false |
| assignedTopics | Array | A list of sys_ids of existing taxonomy topics that control the visibility of the item in the Employee Center portal. For more information, see Associate a catalog item with a taxonomy topic in Employee Center.Note: This property is available only when the Employee Experience Taxonomy plugin (sn_ect) is active. |
| availableFor | Array | A list of sys\_ids of user criteria \[user\_criteria\] that define who can access the item. |
| notAvailableFor | Array | A list of sys\_ids of user criteria \[user\_criteria\] that define who can't access the item.This property overrides the availableFor property. |
| variableSets | Array | A list of variable identifiers of VariableSet objects or sys\_ids of variable sets \[item\_option\_new\_set\] to attach to the item. For more information, see VariableSet object.Format: `{ variableSet, order }` |
| flow | Reference or String | The variable identifier of a Flow object or sys_id of a flow [sys_hub_flow] that defines how the request is fulfilled. To define a flow, use the Flow API - ServiceNow Fluent.Note: You should use flows as the fulfillment method for catalog items. When flow, workflow, and executionPlan are all specified, the system uses the flow. |
| executionPlan | Reference or String | The variable identifier or sys\_id of an execution plan \[sc\_cat\_item\_delivery\_plan\] that defines how the request is fulfilled. To define an execution plan, use the Record API - ServiceNow Fluent. |
| workflow | String | The sys\_id of a legacy workflow \[wf\_workflow\] that defines how the item request is fulfilled. Use the flow property for new implementations. |
| accessType | String | The user access required to request the item.Valid values:
Note: This functionality is only applicable when the item has a Requested For variable. Default: restricted |
| location | Reference or String | The variable identifier or sys\_id of a location \[cmn\_location\] where the item is provided. To define a location, use the Record API - ServiceNow Fluent. |
| vendor | Reference or String | The variable identifier or sys\_id of a vendor associated with the item. To define a vendor, use the Record API - ServiceNow Fluent. |
| deliveryPlanScript | Script | Deprecated. Use the executionPlan property instead. |
| deliveryTime | Object | The estimated time to deliver the item.Format: `deliveryTime: { days: Number, hours: Number })` |
| entitlementScript | Script | A script that defines entitlement for the item. |
| makeItemNonConversational | Boolean | Flag that indicates whether to prevent the ability to request the item from a conversational experience such as Virtual Agent. If true, the item can be requested from a conversational experience.Default: false |
| visibleBundle | Boolean | Flag that indicates whether item is visible in saved bundles.Default: true |
| visibleGuide | Boolean | Flag that indicates whether item is visible in order guides.Default: true |
| visibleStandalone | Boolean | Flag that indicates whether the standalone view is visible.Default: true |
| fulfillmentAutomationLevel | String | The level of fulfillment automation for requests.Valid values: - unspecified: Automation level of item isn’t specified. - manual: Catalog item isn’t automated. - semiAutomated: Catalog item is semi-automated. - fullyAutomated: Catalog item is automated completely. |
| fulfillmentGroup | Reference or String | The variable identifier or sys\_id of the group \[sys\_user\_group\] responsible for delivering the item. To define a user group, use the Record API - ServiceNow Fluent. |
| catalogs | Array | A list of sys\_ids of the catalogs \[sc\_catalog\] in which the item appears. |
| categories | Array | A list of sys\_ids of the categories \[sc\_category\] to which the item belongs. A catalog must be specified in the catalogs property before categories can be assigned.In the Service Portal, catalog searches find only items that are assigned to a category. In Employee Center, catalog searches find only items that are associated with a taxonomy topic. For more information, see Associate a catalog item with a taxonomy topic in Employee Center. |
| cost | Number | A number indicating the one-time cost of the item.Default: 0 |
| displayPriceProperty | String | The system property that controls how the item price is displayed. |
| ignorePrice | Boolean | Flag that indicates whether to hide the item price in the cart and in the catalog listing.Default: true |
| mobileHidePrice | Boolean | Flag that indicates whether to hide the item price on mobile devices.Default: false |
| omitPrice | Boolean | Flag that indicates whether to omit the price entirely from all views of the item.Default: false |
| billable | Boolean | Flag that indicates whether the item is billable.Default: false |
| pricingDetails | Array | A list of pricing entries for the item. Valid values: - price: A one-time price for the item. - recurring\_price: A price that recurs at a regular interval. When using this value, the recurringFrequency property is required. Format: `{ amount, currencyType, field }` |
| recurringFrequency | String | The time interval at which the recurring price repeats, such as monthly or yearly.This property is required when pricingDetails contains a `recurring_price` field entry. |
| requestMethod | String | The label for the submission button and the order submission experience.Valid values:
Default: order |
| customCart | Reference or String | The variable identifier or sys\_id of a custom UI macro to use for cart rendering. To define a custom cart, use the Record API - ServiceNow Fluent. |
| useScLayout | Boolean | Flag that indicates whether the item uses the Service Catalog layout for display.Default: true |
| noCart | Boolean | Deprecated. Flag that indicates whether to hide the shopping cart.Default: false |
| noOrder | Boolean | Deprecated. Flag that indicates whether to hide the Order option.Default: false |
| noOrderNow | Boolean | Deprecated. Flag that indicates whether to hide the Order Now option.Default: false |
| noProceedCheckout | Boolean | Deprecated. Flag that indicates whether to hide the checkout process.Default: false |
| noQuantity | Boolean | Deprecated. Flag that indicates whether to hide the Quantity field.Default: false |
| noSearch | Boolean | Deprecated. Flag that indicates whether to hide search.Default: false |
| $meta | Object | Metadata for the application metadata.With the installMethod property, you can map the application metadata to an output directory that loads only in specific circumstances. Valid values for installMethod:
|
import { CatalogItem } from "@servicenow/sdk/core";
export const softwareLicenseRequest = CatalogItem({
$id: Now.ID["software_license_request"],
name: "Software License Request",
shortDescription: "Request a software license",
catalogs: [serviceCatalog],
categories: [softwareCategory],
// Attach reusable variable sets
variableSets: [
{ variableSet: contactInfoSet, order: 100 },
{ variableSet: approvalInfoSet, order: 200 }
],
// Item-specific variables
variables: {
software_name: SingleLineTextVariable({
question: "Software Name",
mandatory: true,
order: 100
}),
license_type: SelectBoxVariable({
question: "License Type",
choices: {
individual: { label: "Individual", sequence: 1 },
team: { label: "Team (5 seats)", sequence: 2 },
enterprise: { label: "Enterprise (unlimited)", sequence: 3 }
},
mandatory: true,
order: 200
}),
number_of_licenses: SingleLineTextVariable({
question: "Number of Licenses",
defaultValue: "1",
order: 300
}),
justification: MultiLineTextVariable({
question: "Business Justification",
mandatory: true,
order: 400
})
},
// Pricing with recurring charges
pricingDetails: [
{ amount: 0, currencyType: "USD", field: "price" },
{ amount: 99, currencyType: "USD", field: "recurring_price" }
],
recurringFrequency: "monthly",
flow: "523da512c611228900811a37c97c2014",
deliveryTime: { days: 3, hours: 0 }
})
CatalogItemRecordProducer object
Create a record producer [sc_cat_item_producer] for users to create task-based records, such as incident or change request records, from the service catalog.
You can create a record producer for tables and database views that are in the same scope as the record producer. You can also create a record producer for tables that allow create access from applications in other scopes.
| Name | Type | Description |
|---|---|---|
| $id | String or Number | Required. A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys\_id. For more information, see ServiceNow Fluent language constructs.Format: `Now.ID['String' or Number]` |
| table | Reference or String | Required. The variable identifier of a Table object or name of a table in which the record producer creates records, such as incident or change\_request. |
| name | String | Required. A name for the item that appears in the catalog. |
| active | Boolean | Flag that indicates whether the item is active and available to be ordered.Default: true |
| availability | String | The type of device on which the item displays.Valid values: - desktopOnly: The item displays only on desktop devices. - mobileOnly: The item displays only on mobile devices. - both: The item displays on both desktop and mobile devices. Default: desktopOnly |
| checkedOut | Boolean | Flag that indicates whether the item is checked out for editing.Default: false |
| description | String | A detailed description of the item that displays in the catalog when a user selects the item or the associated Preview link.You can embed videos, images, links to internal knowledge base (KB) articles, and links to external sources of information and instruction documentation. |
| meta | Array | A list of metadata tags used to aid in searches related to the item.Note: The meta property is used only for Zing text indexing and search engine and not for AI Search. |
| model | Reference or String | The variable identifier or sys\_id of a product model \[cmdb\_model\] associated with the item. To define a product model, use the Record API - ServiceNow Fluent. |
| order | Number | The order in which the item appears within its category.Default: 0 |
| owner | Reference or String | The variable identifier or sys\_id of a user \[sys\_user\] who owns the item and has edit access to it. To define a user, use the Record API - ServiceNow Fluent. |
| roles | Array | A list of variable identifiers of Role objects or sys\_ids of roles \[sys\_user\_role\] that can access the item. For more information, see Role API - ServiceNow Fluent. |
| shortDescription | String | A short description of the item that appears on the catalog home page, search results, and the title bar of the order form. |
| showVariableHelpOnLoad | Boolean | Flag that indicates whether the item displays variable help text by default.Default: false |
| startClosed | Boolean | Flag that indicates whether to start the item in a collapsed state.Default: false |
| state | String | The publication state of the item, such as draft or published. |
| variables | Object | The variable definitions for the item that provide options for requesting it. Each variable type has a specific function. For example: |
| version | Number | A version of the item.Default: 1 |
| view | Reference or String | Required. The variable identifier or name of the UI view \[sys\_ui\_view\] which applies, or the default view. To define a UI view, use the Record API - ServiceNow Fluent.To use the default view \(`default_view`\), you must import it: |
| icon | String | An image file that displays as an icon beside the item name in the catalog.Use a 27x27 pixel image. If no image is uploaded, the default icon appears. |
| picture | String | An image file to display as a picture of the item. |
| mobilePicture | String | An image to display as a picture of the item on mobile devices.This property applies only if the value of the mobilePictureType is `mobilePicture`. |
| mobilePictureType | String | The type of picture to display for the item on mobile devices.Valid values: - desktopPicture: Use the image from the picture property. - mobilePicture: Use the image from the mobilePicture property. - noPicture: The item doesn't display a picture on mobile devices. Default: desktopPicture |
| assignedTopics | Array | A list of sys_ids of existing taxonomy topics that control the visibility of the item in the Employee Center portal. For more information, see Associate a catalog item with a taxonomy topic in Employee Center.Note: This property is available only when the Employee Experience Taxonomy plugin (sn_ect) is active. |
| availableFor | Array | A list of sys\_ids of user criteria \[user\_criteria\] that define who can access the item. |
| notAvailableFor | Array | A list of sys\_ids of user criteria \[user\_criteria\] that define who can't access the item.This property overrides the availableFor property. |
| variableSets | Array | A list of variable identifiers of VariableSet objects or sys\_ids of variable sets \[item\_option\_new\_set\] to attach to the item. For more information, see VariableSet object.Format: `{ variableSet, order }` |
| hideAddToCart | Boolean | Flag that indicates whether to hide the Add to Cart button.Default: false |
| hideAddToWishList | Boolean | Flag that indicates whether to hide the Add to Wishlist button.Default: false |
| hideDeliveryTime | Boolean | Flag that indicates whether to hide the delivery time.Default: false |
| hideQuantitySelector | Boolean | Flag that indicates whether to hide the Quantity field.Default: false |
| hideSaveAsDraft | Boolean | Flag that indicates whether to hide the Save as Draft button.Default: false |
| hideSP | Boolean | Flag that indicates whether to hide an item on Service Portal.Default: false |
| mandatoryAttachment | Boolean | Flag that indicates whether to require adding an attachment to submit a request.Default: false |
| hideAttachment | Boolean | Flag that indicates whether to hide the attachment section and not support adding attachments.Default: false |
| allowEdit | Boolean | Flag that indicates whether users can edit the created record after submission.Default: false |
| canCancel | Boolean | Flag that indicates whether to display a Cancel button on the record producer form. Users can select Cancel to cancel the record producer and return to the last-viewed screen.Default: false |
| postInsertScript | Script | A server-side script that runs after the record is inserted in the associated table. You can call This property supports inline JavaScript or a reference to another file in the application that contains a script. Format:
Default: |
| redirectUrl | String | The redirect destination after the record is generated.Valid values: - generatedRecord: Redirects to the task record created by the record producer. - catalogHomePage: Redirects to the service catalog. Default: generatedRecord |
| saveOptions | String | Advanced configuration options for saving the record producer. |
| saveScript | Script | A script that runs at every step save in Catalog Builder. This property supports inline JavaScript or a reference to another file in the application that contains a script.Format: - To use text content from another file, refer to a file in the application using the following format: `Now.include('path/to/file')`. For more information, see ServiceNow Fluent language constructs. - To provide an inline script, use string literals or template literals for multiple lines of code: `'Script' or `Script``. Default: |
| script | Script | A server-side script that runs before the record is created. Use this script to assign values to fields on the record dynamically. Don't call `current.update()` or `current.insert()` in this script.This property supports inline JavaScript or a reference to another file in the application that contains a script. Format: - To use text content from another file, refer to a file in the application using the following format: `Now.include('path/to/file')`. For more information, see ServiceNow Fluent language constructs. - To provide an inline script, use string literals or template literals for multiple lines of code: `'Script' or `Script``. Default: |
| image | String | Deprecated. An image for the item. |
| $meta | Object | Metadata for the application metadata.With the installMethod property, you can map the application metadata to an output directory that loads only in specific circumstances. Valid values for installMethod:
|
import { CatalogItemRecordProducer } from "@servicenow/sdk/core";
const serviceCatalog = "e0d08b13c3330100c8b837659bba8fb4";
const itServicesCategory = "d258b953c611227a0146101fb1be7c31";
export const comprehensiveIncidentProducer = CatalogItemRecordProducer({
$id: Now.ID["comprehensive_incident_producer"],
name: "Report Incident with Full Configuration",
shortDescription: "Complete incident producer with variables and scripts",
table: "incident",
catalogs: [serviceCatalog],
categories: [itServicesCategory],
variables: {
short_description: SingleLineTextVariable({
question: "Brief Summary",
mandatory: true,
mapToField: true,
field: "short_description",
order: 100
}),
urgency: SelectBoxVariable({
question: "Urgency",
mandatory: true,
mapToField: true,
field: "urgency",
choices: {
"1": { label: "High", sequence: 1 },
"2": { label: "Medium", sequence: 2 },
"3": { label: "Low", sequence: 3 }
},
order: 200
}),
assignment_group: ReferenceVariable({
question: "Assignment Group",
mapToField: true,
field: "assignment_group",
referenceTable: "sys_user_group",
order: 300
})
},
script: Now.include("../../scripts/rp-pre-insert.js"),
postInsertScript: Now.include("../../scripts/rp-post-insert.js"),
redirectUrl: "generatedRecord",
view: "ess",
allowEdit: true
})
CatalogUiPolicy object
Configure a catalog UI policy [catalog_ui_policy] to control variable behavior on catalog item forms based on conditions.
Catalog UI policies can make variables mandatory, read-only, visible, or hidden when specified conditions are met. For validation, calculations, or asynchronous calls, use catalog client scripts instead.
| Name | Type | Description |
|---|---|---|
| $id | String or Number | Required. A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys\_id. For more information, see ServiceNow Fluent language constructs.Format: `Now.ID['String' or Number]` |
| shortDescription | String | Required. A short description of what the catalog UI policy does. |
| catalogItem | Reference or String | Required only if the variableSet property isn’t used. The variable identifier of a CatalogItem or CatalogItemRecordProducer object or sys\_id of the catalog item \[sc\_cat\_item\] or record producer \[sc\_cat\_item\_producer\] to which the UI policy applies. For more information, see CatalogItem object or CatalogItemRecordProducer object. |
| variableSet | Reference or String | Required only if the catalogItem property isn’t used. The variable identifier of a VariableSet object or sys\_id of the variable set \[item\_option\_new\_set\] to which the UI policy applies. For more information, see VariableSet object. |
| appliesTo | String | The scope to which the UI policy applies.Valid values: - item: The policy applies to a catalog item. - set: The policy applies to a variable set. Default: item |
| active | Boolean | Flag that indicates whether the catalog UI policy is active.Default: true |
| global | Boolean | Flag that indicates on which views of the table the Catalog UI Policy runs.Default: true |
| onLoad | Boolean | Flag that indicates whether the catalog UI policy runs when the form loads. If false, the policy applies only when variable values change.Default: true |
| reverseIfFalse | Boolean | Flag that indicates whether to reverse the UI policy actions when the catalog condition evaluates to false.Default: true |
| inherit | Boolean | Flag that indicates whether the Catalog UI Policy is inherited.Default: false |
| isolateScript | Boolean | Flag that indicates whether the policy scripts run in an isolated scope.Default: true |
| catalogCondition | String | The encoded query conditions based on catalog item variable values that trigger the UI policy. For example: |
| appliesOnCatalogItemView | Boolean | Flag that indicates whether the UI policy applies to catalog items displayed in the order screen. This view is available to requesters.Default: true |
| appliesOnTargetRecord | Boolean | Flag that indicates whether the UI policy applies to records created for task-extended tables via record producers.Default: false |
| appliesOnCatalogTasks | Boolean | Flag that indicates whether the UI policy applies to catalog task forms. This view is available to fulfillers.Default: false |
| appliesOnRequestedItems | Boolean | Flag that indicates whether the UI policy applies to requested item forms. This view is available to fulfillers.Default: false |
| runScripts | Boolean | Flag that indicates whether to run the executeIfTrue and executeIfFalse scripts for this UI policy. Use scripts to apply behaviors beyond read-only, mandatory, or visible, such as targeting a specific role.Default: false |
| executeIfTrue | String | A client-side script that runs when the catalog condition evaluates to true. The script must be wrapped in a `function onCondition() {}` function. |
| executeIfFalse | String | A client-side script that runs when the catalog condition evaluates to false. The script must be wrapped in a `function onCondition() {}` function. |
| runScriptsInUiType | String | The UI type on which the policy scripts run.Valid values: - desktop: Scripts run on the desktop interface. - mobileOrServicePortal: Scripts run on the mobile and Service Portal interfaces. - all: Scripts run on all interfaces. Default: desktop |
| vaSupported | Boolean | Flag that indicates whether the UI policy is supported in Virtual Agent conversations.Default: false |
| actions | Array | A list of variable actions to perform when the catalog condition is met. For more information, see actions array. |
| $meta | Object | Metadata for the application metadata.With the installMethod property, you can map the application metadata to an output directory that loads only in specific circumstances. Valid values for installMethod:
|
import { CatalogUiPolicy } from "@servicenow/sdk/core";
import { hardwareRequestItem } from "./catalog-items/HardwareRequest.now";
export const managerApprovalPolicy = CatalogUiPolicy({
$id: Now.ID["manager_approval_policy"],
shortDescription: "Show manager approval when high priority selected",
catalogItem: hardwareRequestItem,
catalogCondition: `${hardwareRequestItem.variables.priority}=high^EQ`,
actions: [
{
variableName: hardwareRequestItem.variables.manager_approval,
visible: true,
mandatory: true
}
]
})
actions array
Configure the variable actions [catalog_ui_policy_action] that a catalog UI policy performs on variables when its conditions are met.
Each action in the array specifies a variable and the property changes to apply to that variable when the UI policy condition evaluates to true.
| Name | Type | Description |
|---|---|---|
| variableName | String | Required. The variable to which the action applies. |
| visible | Boolean | Flag that indicates whether to make the variable visible.Default: false |
| disabled | Boolean | Flag that indicates whether to turn off the variable.Default: false |
| mandatory | Boolean | Flag that indicates whether to make the variable required.Default: false |
| cleared | Boolean | Flag that indicates whether to clear the variable value when the condition is met.Default: false |
| variableMessage | String | A message to display on the variable when the condition is met.This property applies only if the variableMessageType property has a value. |
| variableMessageType | String | The type of field message.Valid values: - info - warning - error |
| value | String | The value to set on the variable when the condition is met. This property applies only if the valueAction property is set to `setValue`. |
| valueAction | String | The action to take on the variable value when the condition is met.Valid values: - setValue: Sets the variable to the value specified in the value property. - clearValue: Clears the variable value. |
| order | Number | The order in which the action is evaluated relative to other actions.Default: 100 |
| readOnly | Boolean | Flag that indicates whether to make the variable read only.Default: false |
actions: [
{
variableName: laptopRequest.variables.justification,
mandatory: true,
variableMessage: "Justification required for urgent requests",
variableMessageType: "info",
order: 100
},
{
variableName: laptopRequest.variables.manager_approval,
visible: true,
mandatory: true,
order: 200
},
{
variableName: laptopRequest.variables.delivery_date,
visible: true,
order: 300
}
]
CatalogClientScript object
Configure a catalog client script [catalog_script_client] that runs on the client side to control the behavior of a catalog item form.
Use catalog client scripts to validate user input, auto-populate fields, or display alerts on catalog item forms. For simple show/hide, mandatory, and read-only logic, use catalog UI policies instead.
| Name | Type | Description |
|---|---|---|
| $id | String or Number | Required. A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys\_id. For more information, see ServiceNow Fluent language constructs.Format: `Now.ID['String' or Number]` |
| name | String | Required. A unique name for the catalog client script. |
| script | Script | The client-side script to run on the catalog item form. This property supports inline JavaScript or a reference to another file in the application that contains a script.Format: - To use text content from another file, refer to a file in the application using the following format: `Now.include('path/to/file')`. For more information, see ServiceNow Fluent language constructs. - To provide an inline script, use string literals or template literals for multiple lines of code: `'Script' or `Script``. |
| type | String | The event that triggers the client script to run.Valid values: - onLoad: Runs when the form loads. Use for initial setup such as setting field states, default values, and visibility. - onChange: Runs when a specific variable changes. Include an `if (isLoading) return;` guard. - onSubmit: Runs when the form is submitted. Return `false` to block submission. Avoid using GlideAjax in this type because of asynchronous issues. |
| uiType | String | The UI type on which the client script runs.Valid values: - desktop: Applies to the desktop interface. - mobileOrServicePortal: Applies to the mobile and Service Portal interfaces. - all: Applies to all interfaces. Default: desktop |
| active | Boolean | Flag that indicates whether the client script is enabled.Default: true |
| appliesTo | String | Required if using the variableSet property. The scope to which the catalog client script applies.Valid values: - item: The script applies to a catalog item. - set: The script applies to a variable set. Default: item |
| catalogItem | Reference or String | Required only if the variableSet property isn’t used. The variable identifier of a CatalogItem or CatalogItemRecordProducer object or sys\_id of the catalog item \[sc\_cat\_item\] or record producer \[sc\_cat\_item\_producer\] to which the client script applies. For more information, see CatalogItem object or CatalogItemRecordProducer object. |
| variableSet | Reference or String | Required only if the catalogItem property isn’t used. The variable identifier of a VariableSet object or sys\_id of the variable set \[item\_option\_new\_set\] to which the UI policy applies. For more information, see VariableSet object. |
| variableName | String | Required if the value of the type property is `onChange`. The name of the catalog variable that triggers the script when its value changes. |
| appliesOnCatalogItemView | Boolean | Flag that indicates whether the client script applies to catalog items displayed in the order screen of the service catalog. This view is available to requesters.Default: true |
| appliesOnRequestedItems | Boolean | Flag that indicates whether the client script applies to requested item forms after the item is requested. This view is available to fulfillers.Default: false |
| appliesOnCatalogTasks | Boolean | Flag that indicates whether the client script applies to catalog task forms for the item. This view is available to fulfillers.Default: false |
| appliesOnTargetRecord | Boolean | Flag that indicates whether the client script applies to records created for task-extended tables via record producers.Default: false |
| global | Boolean | Flag that indicates whether the client script runs in the global scope.Default: true |
| vaSupported | Boolean | Flag that indicates whether the client script is supported in Virtual Agent conversations.Default: false |
| publishedRef | String | The sys\_id of a published catalog item \[sc\_cat\_item\] or record producer \[sc\_cat\_item\_producer\] that this client script references. |
| $meta | Object | Metadata for the application metadata.With the installMethod property, you can map the application metadata to an output directory that loads only in specific circumstances. Valid values for installMethod:
|
import { CatalogClientScript } from "@servicenow/sdk/core";
import { laptopRequest } from "../catalog-items/laptop-request.now";
CatalogClientScript({
$id: Now.ID["laptop_onload"],
name: "Laptop Request - OnLoad",
script: Now.include("../../client/laptop-onload.js"),
type: "onLoad",
catalogItem: laptopRequest,
active: true,
appliesOnCatalogItemView: true
});
The client script is defined in the laptop-onload.js file referenced from the script property. For example:
function onLoad() {
// Set initial field states
g_form.setReadOnly("estimated_cost", true);
g_form.setValue("estimated_cost", "$0");
g_form.setMandatory("justification", true);
}
VariableSet object
Create a variable set [item_option_new_set] that groups reusable variables for use across multiple catalog items and record producers.
Variable sets are reusable collections of variables that can be attached to catalog items and record producers. Catalog UI policies and client scripts can be scoped to a variable set by setting the appliesTo property to set.
Note:
- Variable sets within a catalog item can’t have the same internal name.
- Within a catalog item, the name of a variable can’t be the same as the title or internal name of a variable set.
- Catalog client scripts and catalog UI policy scripts must refer to the internal name of a variable set, not the title or display name.
| Name | Type | Description |
|---|---|---|
| $id | String or Number | Required. A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys\_id. For more information, see ServiceNow Fluent language constructs.Format: `Now.ID['String' or Number]` |
| title | String | Required. The display title of the variable set. This title appears only if the the displayTitle property is set to true. |
| internalName | String | The internal name of the variable set used for programmatic access through the g\_form API and server-side scripts. If not provided, the internal name is automatically generated from the title property. |
| description | String | A description of the variable set and its intended use. |
| type | String | The type of the variable set.Valid values: - singleRow: Variables are arranged in a single row. - multiRow: Variables are arranged in multiple rows that users can add or remove. Default: singleRow |
| layout | String | The column layout for the variable set.Valid values: - normal: Variables are displayed in a single column. - 2down: Variables are displayed in two columns, one side then the other. - 2across: Variables are displayed in two columns with alternating sides. Default: normal |
| order | Number | The order in which a variable set displays relative to other variable sets on the form.Default: 100 |
| displayTitle | Boolean | Flag that indicates whether to display a collapsible section header for the variable set. If true, the value of the title property is displayed as a collapsible header.Note: Check box variables are grouped under a default title of Options. To use a custom title, add a Label variable with an order value that places it directly above the check box variables. Default: false |
| setAttributes | String | Additional configuration attributes for the variable set as a comma-separated string, such as max_rows=10,collapsible=true. Use the max_rows attribute to set the maximum number of rows for a multi-row variable set.Note: AttachmentVariable, ContainerVariable, HtmlVariable, and CustomVariable types aren’t supported in multi-row variable sets. |
| readRoles | Array | A list of variable identifiers of Role objects or sys\_ids of roles \[sys\_user\_role\] that can view the variable set. For more information, see Role API - ServiceNow Fluent. |
| writeRoles | Array | A list of variable identifiers of Role objects or sys\_ids of roles \[sys\_user\_role\] that can modify variable values in the set. For more information, see Role API - ServiceNow Fluent. |
| createRoles | Array | A list of variable identifiers of Role objects or sys\_ids of roles \[sys\_user\_role\] that can create row instances. For more information, see Role API - ServiceNow Fluent.This property applies only if the value of the type property is `multiRow`. |
| variables | Object | The variable definitions for the item that provide options for requesting it. Each variable type has a specific function. For example: |
| name | String | An optional name for additional identification of the variable set. |
| version | Number | The version of the variable set.Default: 0 |
| $meta | Object | Metadata for the application metadata.With the installMethod property, you can map the application metadata to an output directory that loads only in specific circumstances. Valid values for installMethod:
|
import {
VariableSet,
EmailVariable,
SingleLineTextVariable,
ReferenceVariable
} from "@servicenow/sdk/core";
export const contactInfoSet = VariableSet({
$id: Now.ID["contact_info_set"],
title: "Contact Information",
description: "Standard contact information fields",
type: "singleRow",
layout: "2across",
order: 100,
displayTitle: true,
variables: {
email: EmailVariable({
question: "Email Address",
mandatory: true,
order: 100
}),
phone: SingleLineTextVariable({
question: "Phone Number",
mandatory: true,
order: 200
}),
department: ReferenceVariable({
question: "Department",
referenceTable: "cmn_department",
referenceQualCondition: "active=true",
order: 300
})
}
})