ServiceNow Expeditions #24 – Script Includes Part 2

In this episode, Ola and Ivan dive deep into the three core variations of ServiceNow Script Includes: Dynamic, Static, and Classless. The team breaks down the fundamental differences between these patterns, demonstrating both the classic ES5 notation (Class.create()) and modern ECMAScript 2021 (ES12) syntax (class declaration, constructor, and static keywords).

You’ll learn why Dynamic Script Includes act as parameterized blueprints, how Static Script Includes act as memory-efficient utility libraries, and why Classless Script Includes are a legacy antipattern that pollutes the namespace. Finally, the team inspects out-of-the-box ServiceNow extensible script includes (…SNC), demonstrates how to safely override code without breaking upgrades, and explores how GlideAjax fits into the overall architecture.

✳ 𝐂𝐇𝐀𝐏𝐓𝐄𝐑𝐒 ✳

00: 00 – Intro & recap
00: 43 – Types of Script Includes
01: 25 – Dynamic Script Includes explained
02: 44 – Static Script Includes explained
04: 18 – Classless Script Includes explained
05: 24 – Dynamic example (Classic)
08: 25 – Dynamic example (ES12)
10: 39 – Static example (Classic)
11: 58 – Static example (ES12)
13: 30 – Classless example
15: 18 – OOB extendable Script Includes
18: 00 – Combining Dynamic & Static
19: 36 – Abstract classes & GlideAjax
20: 59 – Outro

✳ 𝐓𝐀𝐊𝐄𝐀𝐖𝐀𝐘𝐒 ✳

Dynamic Script Includes: Designed as parameterized blueprints (classes) instantiated with the new keyword. In modern ES12, they use standard class declarations and constructor() methods instead of Class.create() and initialize().

Static Script Includes: Act as centralized, memory-efficient utility libraries called directly without instantiation. In ES12, every property and function inside must be explicitly declared with the static keyword.

Classless Antipattern: Classless script includes allow only one function per file and bypass object-oriented principles, polluting the global namespace. They are considered a legacy antipattern and should be avoided in modern development.

Testing Class Blueprints: In background scripts, you can verify whether an object was generated from a specific dynamic script include using the instanceof operator.

Upgradeable Extensibility (…SNC Pattern): Out-of-the-box ServiceNow script includes separate baseline logic (IncidentUtilsSNC) from custom overrides (IncidentUtils). Modifying only the non-SNC child class protects your customizations during platform upgrades.

GlideAjax Integration: GlideAjax script includes extend AbstractAjaxProcessor. Under the hood, client-side requests leverage this inheritance to execute server-side methods seamlessly without manual instantiation.

✳ 𝐑𝐄𝐅𝐄𝐑𝐄𝐍𝐂𝐄 ✳

Learn ECMAScript with Earl Duque – https://www.servicenow.com/community/developer-advocate-blog/learn-ecmascript-2021-with-earl-duque/ba-p/2804911
SN Utils – https://www.arnoudkooi.com/

✳ **𝐃𝐈𝐒𝐂𝐋𝐀𝐈𝐌𝐄𝐑** ✳
This video is for educational purposes only. Information is provided as-is without any warranty of accuracy or completeness. Use of this information is at your own risk. We do not hold rights to third-party materials used under fair use for educational objectives. We are not liable for any loss or damage arising from your actions based on the content of this video.