ServiceNow Best Practices · LessonBy Neelima, ServiceNow Architect · Published · Updated · current release · guidance
ServiceNow Scripting best practices
Write server-side code that is fast, safe and upgrade-friendly.
Quick answer
Follow these to keep code performant and maintainable.
Follow these to keep code performant and maintainable.
- Query only the fields and rows you need; add
setLimit(). - Never run a GlideRecord query inside a loop over another query.
- Use
GlideAggregatefor counts and sums. - Centralise reusable logic in Script Includes, not copied business rules.
- Prefer configuration and out-of-the-box features to stay upgrade-safe.
- Guard against recursive business rules.
- Cover critical logic with ATF tests before promoting update sets.
Quick check
+0 XPStreak ×0
Question 1 of 2
What should you avoid inside a query loop?