Coding standards
Quick answer
Naming, logging, error handling and review habits that keep a platform maintainable across teams.
Key takeaways
- Name things by intent so the next admin understands them
- Gate debug logging behind a property
- Review for failure paths and scale, not only correctness
- The common anti patterns are well known, ban them explicitly
Naming and structure
Prefix custom tables and fields with u_ in global scope, or rely on the scope namespace in scoped apps. Name business rules with the intent, not the mechanism, for example Close parent when all children closed rather than BR incident 3.
Logging
Use gs.info, gs.warn and gs.error with a consistent prefix so logs are searchable. Never log personal data or credentials. Wrap verbose logging behind a property so debug output can be switched on in production for one hour rather than living there forever.
var LOG = 'ACME Orders: ';
if (gs.getProperty('x_acme.orders.debug','false') === 'true') {
gs.info(LOG + 'payload ' + JSON.stringify(safePayload));
}Review habits
A short checklist catches most defects.
- Does it run only when it must, with a tight condition
- Does it handle the failure path, not just the happy path
- Is anything hard coded that belongs in a property or a system table
- Will it still work when the record count is a hundred times larger
What to avoid
No synchronous GlideAjax, no GlideRecord in client scripts, no current.update() in before rules, no gs.sleep, and no unfiltered queries in loops. These five account for most performance escalations.
Want to learn this properly?
Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.
Check your understanding
Which practice keeps debug logging safe in production?
- A. Comment it out
- B. Gate it behind a property
- C. Use gs.print
- D. Log to a custom table always
Show answer
B. Gate it behind a property
A property lets you switch verbose logging on briefly and off again.
Which is an anti pattern?
- A. GlideAggregate for counts
- B. GlideRecord inside a client script
- C. Conditions on business rules
- D. Using gs.error for failures
Show answer
B. GlideRecord inside a client script
Client side GlideRecord is synchronous and slow, GlideAjax is the supported route.