ServiceNow extension points are places built into an application’s code where data is sent to custom code, and where the results that custom code returns are taken back in. Custom script includes, UI macros and UI scripts connect to an extension point through registration, so the customization sits outside application code and is less likely to break after an upgrade.
This page explains how extension points work in any application that exposes them.
What an extension point does
An extension point works as a two-way boundary. On the outbound side, the application code reaches the extension point and hands over the data or objects a customization needs. On the return side, the extension point collects what the customization sends back and folds it into the running application. The returned data has to meet the requirements set for that particular extension point, so the person who designs the extension point also decides the expected shape of the result.
The reason this matters is upgrades. Custom code embedded directly in an application’s own scripts often breaks after an upgrade. Keeping the custom logic in separate artifacts, and linking those artifacts at defined points, lets the base code change while the customization keeps plugging into the same place. That separation is the main reason the feature exists.
The three types of extension point
Extension points come in three types, and each sits in a different kind of artifact.
| Type | Where it lives | Typical use | Artifact that connects to it |
|---|---|---|---|
| Scripted | Server-side script includes, which hold JavaScript functions and object classes | Server-side logic that the application calls at a defined point | Custom script include |
| UI | Server-side UI macros, such as HTML extensions | Adding custom content to a UI page without changing that page | Custom UI macro |
| Client | Client-side UI scripting | Modifying forms in the browser | Custom UI script |
Scripted extension points sit inside server-side script includes. A scripted extension point marks the location where data or objects are sent to a registered custom script include, and where the returned results are processed. You create the extension point and add it to a script include in the base application code. When you customize that base application, you create a custom script include and register it against the extension point.
UI extension points sit inside server-side UI macros. An HTML extension is the common example, and it can add headers and footers to the Knowledge Base view page, which is the kb_view UI page, without editing that page directly.
Client extension points sit in client-side UI scripting and are typically used to modify forms. A UI script packages client-side JavaScript for reuse. It can run from a client script, from another client-side script object, or from HTML code, which means one piece of form logic can serve several places on the form.
Where extension points already exist
Some extension points ship with the platform. Pre-defined extension points are embedded in several applications. Several ServiceNow applications ship with predefined extension points, including Coaching, Continual Improvement Management, Customer Service Management, Field Service Management, Knowledge Management, Orchestration and Password Reset. In those applications, you use the points that are already there and do not need to create them.
Some ServiceNow applications ship with predefined extension points, so you use those points without creating them. Customizations that target a pre-defined point add behavior at that point and leave the base code in place. Where no suitable point exists, the same mechanism is available to anyone building a custom application in their own instance. In that case you add the extension points yourself when you build the application.
Creating an extension point and choosing its scope
Planning comes first. Before building, identify where the extension points belong in the application code. Then define their content and structure, including how customizations interact with the code and how the returned data gets processed.
Building the point follows a sequence of three moves:
- Create the extension point and define its custom interface.
- Designate the place in the application code where data goes out to customizations, and the place where results come back.
- Create the artifact that calls the GlideScriptedExtensionPoint – Scoped method. That call identifies the extension point where the registered artifacts run.
Scope is decided when the extension point is created. You can restrict the point to the application scope where it is defined. In that case, registered customizations run in that scope alone. You can also make the point global, so it runs across all scopes. A restricted point keeps registered customizations contained inside one application. A global point lets customizations in any scope attach to it.
Registering a custom artifact
Registration is the step that links a customization to a point. The sequence is:
- Review the listings of available extension points for the type of artifact you are building.
- Select the extension point you need.
- Structure the artifact to match the point’s description, including its requirements and where it fits in the base code.
- Create the artifact and its code while you register it against the point.
Registration creates an extension instance record. That record links the extension point definition to its implementation in your custom artifact. The extension instances are stored in the Extension Instance [sys_extension_instance] table, so the registrations can be read back from that table as well as from code.
How the platform runs registered code
At runtime the flow follows four steps. The application code reaches an embedded extension point. The code uses that point to find the registered artifacts. It sends each of them the appropriate data or objects. Then it collects their output and incorporates the results into the base application.
Each step is a place to look when something goes wrong. The logs covered below show how many instances were found and how many ran, which narrows down whether the lookup or the execution is failing.
Reading registered instances from script
Code that needs the registered instances calls the GlideScriptedExtensionPoint – Scoped API. Its getExtensions method takes the name of the extension point as a String and returns an array of objects, one for each extension instance linked to that point.
The instances the method returns are uninitialized. If the interface includes an initialize method, call it before you call any other method on that instance. Call getExtensions on the RelatedListItemCandidateFilter point, loop over the returned array, call initialize with the table name, parent field, parent sys_id and referenced field, then call getFilterQuery. The registered script includes on that point include RelatedListItemCandidateFilter and RelatedListCIItemCandidateFilter.
Keep the loop in mind when you design a point. Each instance is a separate object, so the code that consumes the array has to loop through all of them.
Debugging and logging
Enable debugging and logging when you create an extension point. Logging helps identify and fix problems with the custom artifacts that register against it.
The debugging tools are the Script Debugger, which requires the script_debugger role, and the Session Log, which requires the log_debugger role. The Script Debugger lets you set breakpoints in script includes, UI macros or UI scripts. For client-side messages, the global jslog() function writes to the debug log.
The logs record activity at each stage. When the extension point finds active extension instances, the log shows how many were found and when. When it executes them, the log shows how many ran, when, how many failed, and the time of each failure.
Frequently asked questions
What is the difference between a scripted and a client extension point? A scripted extension point sits inside a server-side script include and handles server-side logic. A client extension point sits in client-side UI scripting and is typically used to modify forms in the browser.
Do customizations built on extension points survive an upgrade? Extension points are designed to keep custom code separate from the core components of the application. That separation is what helps prevent the customization from breaking after an upgrade, and the extension point itself is embedded in the base application code.
What makes a custom artifact run at an extension point? Registration. Registering the artifact against the point creates an extension instance record that links the two. When the application code reaches the point, it finds those records and runs the linked artifacts.
Can an extension point be limited to one application? Yes. When you create the point, you can restrict it to the application scope where it is defined, so registered customizations run in that scope alone. You can also make it global so it runs across all scopes.
How do I read the registered instances from script? Call getExtensions with the extension point name through the GlideScriptedExtensionPoint – Scoped API. It returns an array of objects. Call the initialize method on each instance, if the interface has one, before calling other methods.
Where should I start when a customization is not running? Check that debugging and logging were enabled when the point was created. The logs show whether any instances were found and whether they ran or failed. Then use the Script Debugger or the Session Log, depending on the role you hold, to step through the artifact code.