← Home
🔥0 DAY
0 XP
Week 2 · Days 610 · 10 min read

Week 2: Server-Side Scripting — Business Rules, Script Includes, and the current/previous Trap

Days 6–10 of the 20-Day ServiceNow Scripting Curriculum

Week 2 is where most ServiceNow bugs are born. Business Rules look simple until you've recursed yourself into a 60-second save. This week you build the muscle memory to pick the right rule type and the right helper for the job.

Who it's for: Anyone who has read a Business Rule but never confidently written one.

BY THE END YOU CAN

  • Pick before/after/async/display correctly the first time
  • Use current and previous without nuking unrelated fields
  • Move logic into a Script Include and call it from anywhere
  • Recognize when a Flow or UI Policy is the better answer

Day 6: Business Rule Types and When to Use Each

GoalExplain before, after, async, and display in one sentence each.

DrillTake a real requirement (e.g. 'auto-assign on insert') and pick the right type. Defend it.

TakeawayBefore = mutate current. After = side effects on other records. Async = expensive work. Display = client-side prep. Pick wrong and you'll fight it for years.

Day 7: current, previous, and the Recursion Trap

GoalDetect a real change with current.field.changesFrom() and avoid infinite loops.

DrillWrite a BR that updates description only when state changes — without calling current.update().

TakeawayIn a before rule, never call current.update() — the framework does it. previous is your diff log; use changes() and changesTo() instead of manual comparisons.

Day 8: Aborting and setAbortAction

GoalBlock a save with a friendly message that the user actually sees.

DrillReject closing an incident with no resolution notes. Show a message, not a stack trace.

Takeawaycurrent.setAbortAction(true) cancels the operation. Pair it with gs.addErrorMessage so the user knows why. Silent aborts are the worst UX in the platform.

Day 9: Script Includes — Reusable Server Libraries

GoalRefactor a 40-line Business Rule into a Script Include with one public method.

DrillBuild an IncidentUtils class with a getPriorityLabel(grIncident) method. Call it from a BR.

TakeawayScript Includes are how you stop copy-pasting. Use prototype-style classes for reuse, client_callable only when GlideAjax needs them. One class, one responsibility.

Day 10: When NOT to Write a Business Rule

GoalReach for UI Policy, Data Policy, Flow Designer, or ACL when they fit better.

DrillTake three requirements; only one should end up as a Business Rule.

TakeawayValidation that runs in browser AND server? Data Policy. Field show/hide? UI Policy. Cross-record orchestration? Flow. BRs are the catch-all, not the default.

PRACTICE THIS WEEK