es5-compliance
ES5 Compliance for ServiceNow
ServiceNow runs on Mozilla Rhino engine which only supports ES5 JavaScript (2009 standard). All server-side scripts MUST use ES5 syntax.
Forbidden Syntax (WILL CAUSE SyntaxError)
| ES6+ Syntax | ES5 Alternative |
|---|---|
const x = 5 |
var x = 5 |
let items = [] |
var items = [] |
() => {} |
function() {} |
`Hello ${name}` |
'Hello ' + name |
for (x of arr) |
for (var i = 0; i < arr.length; i++) |
{a, b} = obj |
var a = obj.a; var b = obj.b; |
[a, b] = arr |
var a = arr[0]; var b = arr[1]; |
...spread |
Use Array.prototype.slice.call() |
class MyClass {} |
Use constructor functions |
async/await |
Use GlideRecord callbacks |
Promise |
Use GlideRecord with callbacks |
Common Patterns
Variable Declarations
// WRONG - ES6
const MAX_RETRIES = 3
let currentUser = gs.getUser()
// CORRECT - ES5
var MAX_RETRIES = 3
var currentUser = gs.getUser()
Functions
// WRONG - Arrow functions
var active = incidents.filter((inc) => inc.active)
var process = () => {
return "done"
}
// CORRECT - ES5 functions
var active = []
for (var i = 0; i < incidents.length; i++) {
if (incidents[i].active) {
active.push(incidents[i])
}
}
var process = function () {
return "done"
}
String Concatenation
// WRONG - Template literals
var message = `Incident ${number} assigned to ${user}`
// CORRECT - String concatenation
var message = "Incident " + number + " assigned to " + user
Loops
// WRONG - for...of
for (var item of items) {
gs.info(item)
}
// CORRECT - Traditional for loop
for (var i = 0; i < items.length; i++) {
gs.info(items[i])
}
Default Parameters
// WRONG - Default parameters
function process(incident, priority = 3) {
// ...
}
// CORRECT - Manual defaults
function process(incident, priority) {
if (typeof priority === "undefined") {
priority = 3
}
// ...
}
Automatic Validation
Before deploying any server-side script:
- Check for
const/letdeclarations - convert tovar - Check for arrow functions
=>- convert tofunction() - Check for template literals
`- convert to string concatenation - Check for destructuring
{a, b}- convert to explicit property access - Check for
for...ofloops - convert to index-based loops
Exception: Client Scripts
Client-side scripts (Client Scripts, UI Policies) run in the browser and MAY support ES6+ depending on user's browser. However, for maximum compatibility, ES5 is still recommended.
More from groeimetai/snow-flow
knowledge-management
This skill should be used when the user asks to "create knowledge article", "KB article", "knowledge base", "knowledge workflow", "article template", "publish article", or any ServiceNow Knowledge Management development.
87reporting-dashboards
This skill should be used when the user asks to "create report", "dashboard", "chart", "visualization", "analytics", "scheduled report", "export data", or any ServiceNow reporting and dashboard development.
77document-management
This skill should be used when the user asks to "attachment", "document", "file upload", "document template", "PDF generation", "document workflow", or any ServiceNow Document Management development.
74predictive-intelligence
This skill should be used when the user asks to "predictive intelligence", "machine learning", "ML", "classification", "similarity", "clustering", "prediction", "AI", or any ServiceNow Predictive Intelligence development.
72vendor-management
This skill should be used when the user asks to "vendor", "supplier", "contract", "procurement", "SLA", "vendor risk", "vendor performance", or any ServiceNow Vendor Management development.
68mcp-tool-discovery
This skill should be used when the user asks about "available tools", "what tools", "how to find tools", "tool search", "MCP servers", "list tools", "discover tools", "which tools", or needs guidance on discovering and using Snow-Flow MCP tools.
68