Function: SPMenu(config)
Parameters
config
SPMenu
Properties:
-
$id (required):
string | number | ExplicitKey<string> -
$meta (optional):
object- installMethod:
'first install' | 'demo'Map a record to an output folder that loads only in specific circumstances. 'first install' - > 'unload', 'demo' -> 'unload.demo'
- installMethod:
-
active (optional, default: true):
booleanWhether this instance is rendered on the page. Set tofalseto hide the instance without deleting it. -
advancedPlaceholderDimensions (optional, default: false):
booleanEnables fine-grained control over placeholder width and height viaplaceholderDimensions. Only relevant whenasyncLoadistrue. -
asyncLoad (optional, default: false):
booleanDefers rendering of this widget until the async trigger condition is met. Use withasyncLoadTriggerto control when loading begins. -
asyncLoadDeviceType (optional):
stringComma-separated list of device types for which async loading is applied. -
asyncLoadTrigger (optional, default: 'viewport'):
'viewport' | 'parallel'Controls when async loading is triggered:'viewport'— loads the widget when it is scrolled into the visible viewport.'parallel'— loads the widget immediately in parallel with other page content.
-
color (optional, default: 'default'):
BootstrapColorBootstrap contextual color applied to the instance header band. Valid values:'default','primary','success','info','warning','danger'. -
column (optional):
string | Record<'sp_column'>Reference to thesp_columnrecord this instance belongs to (used internally). -
css (optional):
stringCSS scoped to this widget instance, applied in addition to the widget's own CSS. -
cssClass (optional):
stringAdditional CSS class name added to the instance wrapper element. -
glyph (optional):
stringFontAwesome icon class (without thefa-prefix) shown alongside the instance title. -
id (optional):
stringUnique string identifier for the instance record (sp_instance.id). -
items (optional):
SPMenuItem[]The menu items for the instance (maps to sp_rectangle_menu_item) -
order (optional):
numberSort order within the column. Lower values appear higher/earlier. -
placeholderConfigurationScript (optional):
stringServer-side script that returns placeholder dimension config dynamically. Evaluated on page load before the widget is asynchronously loaded. -
placeholderDimensions (optional):
JsonSerializableJSON object specifying explicit width/height for the async placeholder. Only used whenadvancedPlaceholderDimensionsistrue. -
placeholderTemplate (optional):
stringAngularJS HTML template rendered as the placeholder while async content loads. -
preservePlaceholderSize (optional, default: false):
booleanMaintains the placeholder element's height while async content is loading, preventing layout shift (CLS). Only relevant whenasyncLoadistrue. -
roles (optional):
(string | Role | Record<'sys_user_role'>)[]Restricts visibility of this instance to users with at least one of the specified roles. If empty, the instance is visible to all users who can access the page. -
shortDescription (optional):
stringBrief admin-facing description of the instance's purpose. Not displayed to end users. -
size (optional, default: 'md'):
SPInstanceSizeVisual size of the instance card in the portal designer. Valid values:'sm','md','lg','xl'. -
title (optional):
stringHeading text displayed above the widget instance in the portal UI. -
url (optional):
stringURL override applied to the instance link/title. -
widget (optional):
string | Record<'sp_widget'> | SPWidgetThe widget (sp_widget) to render at this position on the page. -
widgetParameters (optional):
JsonSerializableJSON key-value pairs passed to the widget's server and client scripts asoptions. Keys correspond to the widget'soptionSchemaproperty names.
Examples
sp-menu-basic
// Source: packages/api/tests/service-portal/menu-plugin.test.ts
import { SPMenu } from '@servicenow/sdk/core'
export const BasicMenuExample = SPMenu({
$id: Now.ID['menu-id'],
title: 'Test Menu',
widget: '5ef595c1cb12020000f8d856634c9c6e',
roles: ['admin', 'itil'],
items: [
{
$id: Now.ID['item-1'],
type: 'page',
label: 'Home',
page: 'bf4aec5377014caca47b4845858ed506',
},
],
})
sp-menu-nested
// Source: packages/api/tests/service-portal/menu-plugin.test.ts
import { SPMenu } from '@servicenow/sdk/core'
export const NestedMenuExample = SPMenu({
$id: Now.ID['menu-id'],
title: 'Nested Menu',
widget: '5ef595c1cb12020000f8d856634c9c6e',
items: [
{
$id: Now.ID['parent-item'],
type: 'page',
label: 'Parent',
page: 'page-id-1',
childItems: [
{
$id: Now.ID['child-item'],
type: 'kb_topic',
label: 'Child',
kbTopic: 'FAQ',
page: 'page-id-2',
},
],
},
],
})
sp-menu-with-roles
// Source: packages/api/tests/service-portal/menu-plugin.test.ts
import { SPMenu } from '@servicenow/sdk/core'
export const MenuWithRolesExample = SPMenu({
$id: Now.ID['menu-id'],
title: 'Test Menu',
widget: '5ef595c1cb12020000f8d856634c9c6e',
roles: ['admin', 'itil'],
active: true,
size: 'md',
color: 'default',
order: 1,
items: [
{
$id: Now.ID['item-1'],
type: 'page',
label: 'Home',
page: 'page-sys-id',
order: 100,
active: true,
glyph: 'empty',
color: 'default',
},
],
})