Developing custom widgets

  • Release version: Australia
  • Updated April 22, 2026
  • 3 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Developing custom widgets

    Develop custom widgets for ServiceNow portals using AngularJS, Bootstrap, and the ServiceNow API. Widgets enable dynamic, reusable components within Service Portal pages, combining client-side and server-side scripting to display data, gather user input, and interact with ServiceNow records.

    Show full answer Show less

    Essential skills include ServiceNow API knowledge for server interactions and AngularJS expertise for client-side data binding and user interface management. Optionally, Bootstrap components can be used to enhance widget design.

    Widget Components

    • HTML Template (mandatory): Defines the user interface with AngularJS for rendering views and binding data.
    • Client Script (mandatory): Acts as the client controller using AngularJS and ServiceNow API to process and pass data between the server and UI.
    • Server Script (mandatory): Handles server-side logic such as querying and updating records, and initializing widget state.
    • Link Function (optional): Allows direct DOM manipulation using AngularJS.
    • Option Schema (optional): Enables configuration parameters for widget instances, allowing administrators to customize widget behavior per instance.
    • Angular Providers (optional): Facilitate data sharing, state persistence, and reusable logic across multiple widgets, improving performance and maintainability.
    • Dependencies (optional): External JavaScript or CSS resources linked to widgets for additional functionality or styling.

    Global Objects and Data Flow

    During widget rendering, the server script accesses global objects: input (data from client, initially undefined), options (initialization parameters), and data (used to send data to the client). The client accesses server data via c.data and can update data using server.update(), which synchronizes client and server states. The c.options object provides read-only access to widget invocation parameters.

    Development Environment

    The Widget Editor in Service Portal Configuration offers an integrated development environment (IDE) to create and edit widgets with real-time preview. It supports modern JavaScript standards (ECMAScript 2021) for server-side scripting.

    Best Practices and Resources

    • Follow general guidelines for optimal performance and scalable development.
    • Use the tutorial to build example widgets and understand advanced scripting.
    • Leverage cloning of existing widgets to accelerate development.
    • Define option schemas to allow flexible widget configuration.
    • Use Angular Providers to maintain shared state and reusable logic, enhancing portal responsiveness.
    • Embed widgets within other widgets or forms to modularize functionality.
    • Manage widget dependencies by linking to external JavaScript and CSS libraries as needed.
    • Internationalize widgets with ${} or gs.getMessage() syntax for localization support.
    • Replace legacy UI Macros with widgets to modernize Service Catalog forms.
    • Use available troubleshooting tools to diagnose and fix unexpected widget behavior.

    Develop custom widgets for portals using AngularJS, Bootstrap, and the ServiceNow API.

    Before you begin

    To develop widgets, you need ServiceNow API experience to:
    • Run record queries on the server.
    • Create and update records.
    You need AngularJS experience to:
    • Bind variables to client controllers.
    • Access server objects in a widget.
    • Gather user input.

    Optionally, you can build on the Bootstrap template by accessing Bootstrap components.

    Parts of a widget

    Like Angular directives, widgets execute a specified behavior within a Service Portal page. A widget includes mandatory and optional scripting components.

    HTML template

    A mandatory widget component.

    The HTML template requires knowledge of AngularJS to display and gather data. Use the HTML template to:

    • Render the dynamic view that a user sees in the browser using information from the model and controller.
    • Bind client script variables to your markup.
    • Gather data from the end user.
    Client script

    A mandatory widget component.

    A client script requires knowledge of both the ServiceNow API and AngularJS to create a client controller. Use the client script to:

    • Map server data from JavaScript and JSON objects to client objects.
    • Process data before rendering it.
    • Pass data to the HTML template.
    • Pass user input and data back to the server for processing.
    Server script

    A mandatory widget component.

    A server script requires knowledge of the ServiceNow API to work with record data. Use the server script to:

    • Set the initial state of the widget.
    • Send record data to the widget client script using the data variable.
    • Run server-side queries.
    Link function

    An optional widget component.

    The link function requires knowledge of AngularJS. Use a link function to directly manipulate the DOM.

    Option schema

    An optional widget component.

    Enables a Service Portal admin to configure a widget. Use the option schema to:

    • Specify the parameters for a widget.
    • Enable admin users to define instance options for a widget instance.
    • Develop flexible, reusable widgets.
    Angular Providers

    An optional widget component.

    Angular Providers require knowledge of AngularJS. Use Angular Providers to:

    • Keep widgets in sync when changing records or filters.
    • Share context between widgets.
    • Maintain and persist state.
    • Create reusable behaviors and UI components and inject them into multiple widgets.
    Dependencies

    An optional widget component.

    A widget dependency is an external resource used by your widget such as JavaScript or CSS files.

    Global objects in widgets

    When a widget begins to render for the first time on a page, the server script executes first and accesses three global objects: input, options, and data. Because the input variable is a data object sent from the client script, this variable is undefined when first initialized.

    Available variables in server and client script global.

    When a widget is first instantiated, the server script:

    1. Initializes an empty data object.
    2. Initializes the input object with any data sent from the client controller, or the options object with any data used to initialize the widget.
    3. Sends the data object to the client controller as JSON.

    The client script:

    1. Accesses the server data object using c.data.

      Note:
      By default, widgets use the c variable to represent the controller instance using controller as syntax. You can change this variable when creating or copying widgets.
    2. Uses server.update() to post changes to the data model. This method updates the server script using the input object.

      Note:
      After calling server.update(), the client script data object is automatically overwritten by the server script data object.
    3. Uses c.options to access the values used to invoke the widget on the server. This object is read-only.

    Using the Widget Editor

    When you create a widget, a record is created in the sp_widget table. However, you can use the Widget Editor in Service Portal Configuration as your scripting environment. The Widget Editor is a full page application similar to an IDE. You can show the parts of the widget you want to edit and hide the rest, while previewing your changes in real time.

    Note:
    For server-side scripts, you can turn on using the ECMAScript 2021 (ES12) JavaScript mode if your application uses ES5 Standards mode or Compatibility mode. Scripts in applications with the JavaScript mode set to ECMAScript 2021 (ES12) use ECMAScript 2021 (ES12) by default. For more information, see .

    Widget Editor in Service Portal Configuration as a script editor.