Developer Reference

ServiceNow Code Patterns

Reusable architectural patterns with working code and trade-off analysis

advancedXanadu

ACL Design Pattern for Complex Organizations

Use this pattern when your organization has multi-dimensional data access requirements that cannot be satisfied by simple role inheritance alone, such as regional managers who need access to their geographic area across multiple departments, or compliance scenarios where data visibility depends on changing business relationships. This pattern is ideal when performance is critical and you need to minimize the number of ACL evaluations while maintaining precise security boundaries.

View pattern →
intermediateXanadu

API Authentication Strategy Pattern

Use this pattern when your ServiceNow instance has multiple API integrations requiring different authentication methods, when you need centralized management of API credentials and tokens, or when compliance requirements demand detailed audit trails for API authentication events. This pattern is essential for enterprise environments with complex integration landscapes.

View pattern →
advancedXanadu

ATF Test-Driven Development Pattern

Use this pattern when developing new features or major enhancements where requirements are well-defined and code quality is critical. It's particularly valuable for complex business logic, integrations, or functionality that will be maintained by multiple developers over time.

View pattern →
intermediateXanadu

Approval Chain Design Pattern

Use this pattern when you need approval workflows that vary based on record attributes like amount, department, or category, when you require multiple approval stages with different logic for each stage, or when you need to support complex approval scenarios like parallel approvals within a stage followed by sequential escalation. This pattern is ideal for purchase requisitions, change requests, or any process where approval requirements are dynamic and business rules are complex.

View pattern →
advancedXanadu

Async Processing Pattern for Long-Running Operations

Use this pattern when business rules perform operations that take more than a few seconds, such as bulk record updates, complex calculations across large datasets, or multiple external API calls. It's essential when users report slow form saves, transaction timeout errors, or when operations involve processing hundreds or thousands of records.

View pattern →
intermediateXanadu

Automated Assignment Rules Pattern

Use this pattern when you have high-volume work items that require consistent, fair distribution across team members and when assignment criteria are complex enough to benefit from automation. This is particularly valuable in service desk environments with multiple skill sets, varying workloads, or time-sensitive SLA requirements.

View pattern →
intermediateXanadu

Bulk Data Sync via Import Sets Pattern

Use this pattern when importing large datasets from external systems on a scheduled basis, when you need detailed error reporting and data validation during import processes, or when importing data that requires complex field mapping and coalescing logic. This pattern is ideal for nightly data feeds, bulk user imports, or asset synchronization from external CMDBs.

View pattern →
intermediateXanadu

Bulk Record Operation Pattern

Use this pattern when you need to update more than 1,000 records at once, perform data migrations or cleanup operations, or execute bulk updates that might take more than a few seconds to complete. It's essential for scheduled maintenance tasks, data correction scripts, and migration utilities.

View pattern →
advancedXanadu

CI/CD Pipeline Pattern for ServiceNow

Use this pattern when you have multiple ServiceNow instances (dev, test, prod) with regular deployments, need automated testing validation before promotion, require change management approval workflows, or have compliance requirements for deployment traceability. This is essential for large teams with frequent releases or regulated industries requiring deployment documentation.

View pattern →
advancedXanadu

CMDB Data Model Design Pattern

Use this pattern when implementing a new CMDB, redesigning an existing one that has grown organically, or when you need to integrate multiple data sources into a unified configuration model. This is essential for organizations that require accurate impact analysis, automated service mapping, or comprehensive change risk assessment.

View pattern →
intermediateXanadu

Caching Expensive GlideRecord Queries Pattern

Use this pattern when you have expensive queries that execute frequently with the same parameters, such as configuration lookups, reference data retrieval, or complex aggregate calculations. It's particularly valuable for data that changes infrequently but is accessed often, like organizational hierarchies, system properties, or catalog categories.

View pattern →
intermediateXanadu

Catalog Fulfillment Pipeline Pattern

Use this pattern when you have multiple catalog items with varying fulfillment requirements that need standardization, or when you're experiencing inconsistent processing times and unclear accountability in your current catalog workflows. This pattern is ideal for organizations with mature ITSM processes that need to scale catalog operations efficiently.

View pattern →
advancedXanadu

Change Management Automation Pattern

Use this pattern when managing high-volume change environments where manual processes create bottlenecks and inconsistent risk assessments. It's ideal for organizations with mature CMDB data and established testing frameworks that need to scale change management while maintaining governance controls.

View pattern →
intermediateXanadu

Client-Side Performance Optimization Pattern

Use this pattern when forms or lists are experiencing slow load times, when you have multiple onLoad client scripts executing expensive operations, or when users report sluggish interface performance. This is especially valuable for high-traffic forms with complex business logic or forms that load large amounts of related data that users don't always need.

View pattern →
intermediateXanadu

Dashboard and Report Performance Pattern

Use this pattern when dashboards take more than 3-5 seconds to load, when reports frequently time out or cause performance issues, or when you have widgets that perform complex calculations on large datasets. This pattern is particularly valuable for executive dashboards, operational reports that refresh frequently, and any reporting that aggregates data across multiple tables with thousands of records.

View pattern →
advancedXanadu

Data Archiving Strategy Pattern

Use this pattern when your ServiceNow instance has tables growing beyond 2-3 million records, when report and list performance is degrading due to large datasets, or when you need to meet compliance requirements for data retention while maintaining system performance. This is particularly valuable for incident, change, task, and audit tables in mature ServiceNow implementations.

View pattern →
advancedXanadu

Domain Separation Design Pattern

Use domain separation when you need strict data isolation between business units, subsidiaries, customers, or geographical regions within a single ServiceNow instance. This pattern is ideal for managed service providers serving multiple customers, large enterprises with independent business units, or organizations with regulatory requirements for data segregation.

View pattern →
beginnerXanadu

Dynamic Default Value Pattern

Use this pattern when you need to reduce user input effort by intelligently pre-filling form fields based on context, user attributes, or related data. It's particularly valuable in catalog items, incident forms, and any scenario where default values depend on dynamic conditions rather than static business rules.

View pattern →
intermediateXanadu

Enterprise vs Mid-Market ServiceNow Configuration Pattern

Use enterprise patterns when you have over 5,000 users, multiple business units with distinct processes, complex compliance requirements, or need extensive customization with formal change management. Apply mid-market patterns for organizations under 2,000 users seeking rapid deployment with minimal customization and streamlined governance.

View pattern →
advancedXanadu

Event-Driven Architecture Pattern in ServiceNow

Use this pattern when you have complex business processes that involve multiple systems, lengthy operations that could impact user experience, or when you need to integrate multiple loosely-coupled components that shouldn't directly depend on each other. It's particularly valuable when building scalable solutions that need to handle high transaction volumes or when you want to improve maintainability by separating detection logic from processing logic.

View pattern →
advancedXanadu

High Availability Design Pattern

Use this pattern for mission-critical ServiceNow implementations where downtime directly impacts business operations, revenue, or regulatory compliance. It's essential for organizations with strict SLA requirements, global operations requiring 24/7 availability, or systems that serve as single sources of truth for critical business processes.

View pattern →
advancedXanadu

Hub-and-Spoke Instance Architecture Pattern

Use this pattern when your enterprise has multiple business units requiring ServiceNow customization autonomy but needs centralized reporting, governance, and master data management. This is ideal for large corporations with subsidiaries, global organizations with regional requirements, or companies that have grown through acquisitions and need to consolidate ServiceNow footprints.

View pattern →
advancedXanadu

Inbound API Rate Limiting Pattern

Use this pattern when exposing public-facing or high-volume REST APIs that need protection from abuse, DoS attacks, or runaway client applications. It's essential for APIs that perform expensive operations, access sensitive data, or integrate with external systems that have their own rate limits.

View pattern →
advancedXanadu

Instance Clone Management Pattern

Use this pattern when managing multiple ServiceNow environments that require regular data refreshes while maintaining environment-specific configurations like integrations, credentials, and custom properties. This is essential for enterprise implementations with complex development workflows, strict security requirements, and coordinated release schedules.

View pattern →
advancedXanadu

Integration Error Dead Letter Queue Pattern

Use this pattern when building critical integrations that cannot afford to lose data during temporary outages or when processing high-volume integrations where occasional failures are expected. This is essential for systems that must guarantee message delivery or provide audit trails for compliance requirements.

View pattern →
advancedXanadu

Large Table Query Optimization Pattern

Use this pattern when querying tables with over 100,000 records, especially tables that grow continuously like audit logs, metrics, or transaction records. Apply these techniques when experiencing query timeouts, slow dashboard loading, or when building reports on large historical datasets.

View pattern →
intermediateXanadu

List View Performance Optimization Pattern

Use this pattern when list views take more than 5-10 seconds to load, when dealing with tables containing over 100,000 records, or when users frequently filter on specific columns. This pattern is essential for high-volume production instances where list performance directly impacts productivity.

View pattern →
advancedXanadu

MID Server Load Balancing Pattern

Use this pattern when you have high-volume integrations that exceed single MID Server capacity, need geographic distribution of MID Servers for network access or compliance reasons, or require high availability for mission-critical integrations. This pattern is essential for large enterprises with multiple data centers, extensive discovery requirements, or integration workloads that must continue operating during maintenance windows.

View pattern →
intermediateXanadu

Modular Service Portal Architecture Pattern

Use this pattern when building multiple Service Portals across an organization, when you need to maintain consistent branding and functionality across portals, or when you anticipate significant portal customization requirements. This pattern is essential for organizations with complex portal requirements, multiple business units sharing common functionality, or environments where portal widgets need frequent updates without impacting stability.

View pattern →
advancedXanadu

Multi-System Data Reconciliation Pattern

Use this pattern when you have multiple authoritative systems providing overlapping data about the same entities, such as HR systems and Active Directory both providing user information, or multiple CMDBs providing asset data. This pattern is essential for enterprise environments where data consistency and auditability are critical compliance requirements.

View pattern →
advancedXanadu

Multi-Tenant ServiceNow Architecture

Use this pattern when serving multiple distinct customer organizations, business units with different compliance requirements, or when offering ServiceNow as a managed service. It's essential when tenants require different customizations, have varying security requirements, or when regulatory compliance demands data isolation.

View pattern →
advancedXanadu

Outbound REST Retry and Circuit Breaker Pattern

Use this pattern when integrating with external APIs that may experience intermittent failures, rate limiting, or temporary outages, especially in high-volume integration scenarios. It's essential for mission-critical integrations where service availability directly impacts business operations and when you need to prevent cascade failures from propagating through your ServiceNow instance.

View pattern →
intermediateXanadu

Real-Time vs Batch Integration Decision Pattern

Use this decision pattern when designing integrations between ServiceNow and external systems where you need to choose between immediate synchronization and scheduled bulk transfers. This is particularly valuable for incident management systems requiring real-time notifications, HRMS integrations with varying urgency levels, or CMDB synchronization with discovery tools.

View pattern →
intermediateXanadu

Recursive GlideRecord Avoidance Pattern

Use this pattern when traversing hierarchical data structures that could exceed 500-1000 levels deep, such as deeply nested organizational charts, product categories, or approval workflows. It's essential when working with user-generated hierarchies where depth cannot be controlled or predicted.

View pattern →
intermediateXanadu

Reusable GlideAjax Script Include Pattern

Use this pattern when client scripts need to retrieve server data, perform complex calculations, or execute operations requiring server-side APIs like GlideRecord queries, web service calls, or privileged system functions. It's ideal for form validations, dependent field population, and real-time data lookups without page refreshes.

View pattern →
intermediateXanadu

Robust Script Error Handling Pattern

Use this pattern in Business Rules, Script Includes, Scheduled Jobs, and other server-side scripts that perform operations which could fail due to external dependencies, data validation issues, or unexpected system states. It's particularly valuable when building integrations with external systems, processing user input, or performing complex data transformations where failures need to be handled gracefully.

View pattern →
advancedXanadu

Row-Level Security Pattern

Use this pattern when you need to enforce data segregation within a single table based on user attributes, such as restricting sales representatives to see only their assigned accounts, limiting HR personnel to employee records in their region, or ensuring multi-tenant applications properly isolate customer data. This pattern is ideal for compliance requirements that mandate strict data access controls and audit trails.

View pattern →
intermediateXanadu

SLA Escalation Design Pattern

Use this pattern when you need automated SLA monitoring with multi-stage escalation workflows, particularly in enterprise environments with complex support structures and strict compliance requirements. This approach is essential when manual SLA monitoring is insufficient and you need guaranteed escalation paths that execute reliably even during high-volume periods.

View pattern →
advancedXanadu

Safe Deployment and Rollback Pattern

Use this pattern for critical production deployments, major feature releases, or when deploying changes that affect core business processes or large user populations. This pattern is essential when your organization has strict SLA requirements, compliance obligations, or when the cost of deployment failures is high.

View pattern →
intermediateXanadu

Scheduled Job Distribution Pattern

Use this pattern when you have multiple scheduled jobs that could run at flexible times, when experiencing database performance issues during peak hours, or when managing large ServiceNow instances with dozens of scheduled jobs. This is especially valuable in environments where job timing isn't strictly dictated by business requirements.

View pattern →
intermediateXanadu

Scoped App vs Global Scope Decision Pattern

Use this pattern when planning new ServiceNow customizations or refactoring existing ones, especially for complex implementations that will undergo regular platform upgrades. Apply this pattern when building reusable components that may be distributed across multiple instances or when implementing functionality that requires clear separation from core platform configuration.

View pattern →
advancedXanadu

Script Include Inheritance Pattern

Use this pattern when you have multiple Script Includes that share common functionality but require specialized behavior, such as different types of integrations, notification handlers, or data processors. It's ideal when you want to enforce consistent interfaces across related classes while avoiding code duplication.

View pattern →
intermediateXanadu

Script Include Utility Library Pattern

Use this pattern when you have business logic or data access code that needs to be shared across multiple scripts, applications, or scopes. It's ideal for complex calculations, external system integrations, data transformation utilities, or any functionality that would otherwise be duplicated in multiple places.

View pattern →
advancedXanadu

Sensitive Data Masking Pattern

Use this pattern when handling personally identifiable information (PII), financial data, healthcare records, or any sensitive information that requires regulatory compliance such as PCI DSS, HIPAA, or GDPR. This pattern is essential for organizations that need to maintain detailed audit trails while ensuring sensitive data remains protected from unauthorized access.

View pattern →
intermediateXanadu

Service Account Management Pattern

Use this pattern when building REST API integrations, scheduled imports, web services connections, or any automated system that needs to authenticate to ServiceNow. It's essential for enterprise environments where security compliance requires segregated service accounts with audit trails and regular credential rotation.

View pattern →
advancedXanadu

Service Catalog Architecture at Scale

Use this pattern when your organization has more than 50 catalog items, multiple departments or business units contributing catalog content, or when you're experiencing inconsistent user experiences and high maintenance overhead. This pattern is essential for enterprises with complex approval chains, multiple fulfillment teams, and regulatory compliance requirements.

View pattern →
advancedXanadu

ServiceNow Microservices Integration Pattern

Use this pattern when ServiceNow needs to integrate with cloud-native applications, containerized microservices, or when you're implementing event-driven architecture across multiple systems. This is ideal for organizations adopting DevOps practices where ServiceNow participates in CI/CD pipelines or when you need to maintain data consistency across distributed systems without tight coupling.

View pattern →
advancedXanadu

ServiceNow Platform Governance Framework Pattern

Use this pattern when managing enterprise ServiceNow instances with multiple developers, regulatory compliance requirements, or complex change management processes. It's essential for organizations that need to maintain strict code quality standards, require audit trails for all platform changes, or integrate ServiceNow development with existing IT governance frameworks.

View pattern →
intermediateXanadu

Update Set Branching Pattern

Use this pattern when you have multiple developers working on related features that may affect the same tables, applications, or business processes simultaneously. It's particularly valuable for large development teams working on major releases or when you need to maintain separate development tracks for different versions or customer implementations.

View pattern →
intermediateXanadu

Webhook Listener Pattern in ServiceNow

Use this pattern when you need to receive real-time notifications from external systems, process third-party service callbacks, or integrate with SaaS applications that push data via webhooks. It's ideal when you need guaranteed delivery, audit trails, and the ability to replay failed processing attempts.

View pattern →