GlideAjax exists because client scripts can't directly execute server-side code — they run in the browser, not on the ServiceNow server. The platform forces an asynchronous callback pattern that trips up developers expecting synchronous behavior. You cannot store the Ajax response in a variable and use it immediately; the callback executes after your function completes. Most GlideAjax failures stem from fighting this async nature instead of embracing it.

When to use this

  • When you need server-side data lookup in a client script that requires database queries or ACL enforcement
  • When you need to validate user input against server-side business rules before form submission
  • When populating reference fields or choice lists based on complex server-side logic
  • When you need to call a utility function that exists in a server-side Script Include from multiple client scripts

When NOT to use this

  • Don't use for simple field manipulations that client scripts can handle directly — use g_form.setValue() or g_form.clearValue() instead
  • Don't use in loops or rapid-fire events like onKeyUp — you'll flood the server with requests and degrade performance
  • Don't use for operations that modify data — use UI Actions or form submission instead to maintain proper audit trails
  • Don't use for time-sensitive operations where the async delay will create poor user experience

Key behaviors and gotchas

  • The Script Include method name must match exactly what you pass to sysparm_name — case sensitive, no typos allowed
  • Script Include must be client callable and extend AbstractAjaxProcessor — missing either breaks the Ajax call silently
  • Always check for null, undefined, or empty responses in your callback — server errors return 'null' as a string
  • Use getXMLAnswer() for simple string returns, getXMLWait() blocks the browser and should be avoided
  • Parameters are automatically URL-decoded, so special characters in values are handled transparently
  • Cross-scope calls require the Script Include to be in Global scope or marked as accessible from your application scope
⚠️

Never try to return the Ajax response from your function — the callback executes after the function completes. Store form updates inside the callback function, not after the Ajax call.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime