← Home
🔥0 DAY
0 XP
Week 3 · Days 1115 · 9 min read

Week 3: Client-Side Scripting and GlideAjax — Without Touching the DOM

Days 11–15 of the 20-Day ServiceNow Scripting Curriculum

Client-side scripting is where new devs reach for jQuery and burn a week on a UI Builder upgrade. This week you'll write Client Scripts that survive every UI ServiceNow has shipped — Classic, Service Portal, Next Experience, UI Builder.

Who it's for: Devs who write Client Scripts that 'work locally' but break in Portal or Workspace.

BY THE END YOU CAN

  • Pick onLoad vs onChange vs onSubmit without thinking
  • Call a Script Include from the client without freezing the browser
  • Stop using document.getElementById in ServiceNow forever
  • Validate forms on the client AND the server

Day 11: onLoad, onChange, onSubmit — the Trinity

GoalWire the right lifecycle to the right requirement.

DrillDefault a field on load, react to a category change, and block submit if both are empty.

TakeawayonLoad = set initial state. onChange = react. onSubmit = last-chance validation. Use g_form, never DOM.

Day 12: g_form — The Only API You Need on the Form

GoalRead, set, hide, mandate, and clear fields without touching HTML.

DrillMake assigned_to mandatory only when priority = 1.

Takeawayg_form.setMandatory, setVisible, setValue, clearValue, addInfoMessage. These work in Classic, Portal, and Workspace. DOM access does not.

Day 13: GlideAjax — Async Calls from Client to Server

GoalCall a client_callable Script Include and read the result without blocking the form.

DrillLook up a user's manager's email when the caller changes. Show it as an info message.

TakeawayAlways use getXMLAnswer with a callback. Never use synchronous mode — it freezes the browser and is being removed.

Day 14: Building a client_callable Script Include

GoalExtend AbstractAjaxProcessor and expose one method per use case.

DrillBuild UserLookupAjax with getManagerEmail(). Call it from yesterday's Client Script.

Takeawaythis.getParameter('sysparm_user') reads the input. return on the function ends up as the XML answer. Keep methods small; one method per Ajax call.

Day 15: Client Validation + Server Validation = Trust

GoalValidate on the client for UX, on the server for security.

DrillReject a numeric field over 1000 in a Client Script AND a Business Rule.

TakeawayClient validation is a courtesy. Anyone can bypass it via REST or a background script. Always mirror critical rules server-side.

PRACTICE THIS WEEK