What This Table Is

The sp_widget table stores the complete definition of Service Portal widgets — reusable components that render content on Service Portal pages. Each record contains the HTML template, CSS styling, client-side controller JavaScript, and server-side script that make up a widget. The table serves as the configuration layer for all portal functionality, from simple data displays to complex interactive forms.

This table belongs to the Service Portal module and supports the entire portal rendering process. When a user requests a Service Portal page, the platform queries sp_widget records to assemble the page content. The widget's server script executes first, followed by the HTML template rendering, then the client controller loads in the browser.

The sp_widget table extends the base sys_metadata table but contains no child table extensions. Widget instances on specific pages are tracked in separate tables like sp_instance and sp_container, which reference back to widget definitions in this table.

Most enterprise instances contain 200-800 widget records. Out-of-box ServiceNow ships with around 150 widgets, and customers typically create 50-200 custom widgets over time. The table experiences moderate query volume during portal page loads but low write activity — widgets are created during development and rarely modified in production.

When You'll Script Against This Table

You'll query sp_widget primarily in Script Includes that support Service Portal functionality, Migration Set Transform Maps when deploying widgets between instances, and Background Scripts during widget maintenance. Business Rules on this table are rare but useful for enforcing widget development standards or triggering related configuration updates.

Access requires the sp_admin role for write operations, though users with sp_portal can read widget definitions. Widget server scripts execute in the Service Portal application scope, inheriting the portal user's roles plus any elevated permissions configured for the widget.

Common scripting patterns:

  • Finding widgets by id (the technical name) for dynamic portal configuration
  • Querying by category to build widget picker interfaces
  • Reading option_schema to validate widget instance configuration
  • Updating css or template fields for programmatic widget maintenance
  • Filtering by public field to control widget visibility in the designer
  • Copying widget definitions for customization while preserving the original
  • Analyzing widget dependencies by parsing script and client_script for API usage

Table Gotchas

⚠️

The template, script, client_script, and css fields contain large text blocks. Querying multiple widgets without field restrictions can cause performance issues and exceed script execution limits.

⚠️

Widget IDs must be unique and follow JavaScript variable naming conventions since they're used as Angular module names. Special characters will break portal rendering.

  • The option_schema field stores JSON but as a string type — parse it before use and handle malformed JSON gracefully
  • Widget records cache aggressively — changes may not appear immediately in portals, especially in development instances with multiple browser tabs open
  • The servicenow boolean identifies out-of-box widgets — never set this to true on custom widgets as it affects upgrade behavior
⚠️

Widget server scripts run in a different execution context than standard Business Rules. They have access to a special 'data' object and '$sp' API but cannot use standard GlideRecord transaction methods.

  • Deleting widgets doesn't automatically clean up their instances on pages — orphaned sp_instance records can cause portal errors
Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime

The sp_widget table extends sys_metadata, inheriting application scope and update set tracking. Widget definitions connect to the broader Service Portal ecosystem through several key relationships that developers frequently traverse in queries.

The sp_instance table stores individual widget placements on pages, referencing sp_widget through its widget field. The sp_page table defines portal pages that contain widget instances. Developers often join these three tables to understand complete page composition. The sp_dependency table tracks JavaScript and CSS dependencies that widgets require, linking back to widget records through dependency maps.

When building comprehensive Service Portal queries, you'll frequently cross-reference the sp_portal table to understand portal-specific configurations, and the sys_scope table to identify which application owns custom widgets. The sys_update_set relationship becomes crucial during widget deployments between instances.