IT CanvassTalk to an advisor
Development · LessonBy , ServiceNow Trainer, 8 yrs · Published · current release · intermediate

GlideAjax (async)

Call server-side Script Includes from the browser without freezing the form.

Quick answer

GlideAjax is how a client script asks the server a question, 'what is this user's manager?', 'is this value unique?', and gets an answer asynchronously, without blocking the browser. It is the correct, performant alternative to synchronous lookups that freeze the form.

Key takeaways
  • Two halves
  • Why it matters
  • Try it Yourself

GlideAjax is how a client script asks the server a question, 'what is this user's manager?', 'is this value unique?', and gets an answer asynchronously, without blocking the browser. It is the correct, performant alternative to synchronous lookups that freeze the form.

Two halves

You write a client-callable Script Include (extending AbstractAjaxProcessor) and call it from the client with GlideAjax.

// Script Include (server): client callable = true var GetManager = Class.create(); GetManager.prototype = Object.extendsObject(AbstractAjaxProcessor, { managerName: function() { var u = new GlideRecord('sys_user'); u.get(this.getParameter('sysparm_user')); return u.manager.getDisplayValue(); }, type: 'GetManager' });
// Client script var ga = new GlideAjax('GetManager'); ga.addParam('sysparm_name', 'managerName'); ga.addParam('sysparm_user', g_form.getValue('caller_id')); ga.getXMLAnswer(function(answer) { g_form.setValue('u_manager', answer); });
Always use the async callback. Prefer getXMLAnswer (or getXML) with a callback. The synchronous variants (getXMLWait) block the browser and are strongly discouraged, they are the classic cause of 'the form hangs' complaints.

Why it matters

GlideAjax keeps forms responsive while still reaching real server data and logic. Combined with a well-factored Script Include, the same server method serves client scripts, business rules and widgets.

Try it YourselfJavaScript
▸ Press Run to execute.

Runs in a sandbox in your browser. Mock gs and GlideRecord and sample data are provided.

Practice challenge

+0 XPStreak ×0
Question 1 of 3
GlideAjax lets a client script...

Frequently asked questions

What does the term GlideAjax (async client-server) refer to in ServiceNow?
GlideAjax is how a client script asks the server a question, 'what is this user's manager?', 'is this value unique?', and gets an answer asynchronously, without blocking the browser. It is the correct, performant alternative to synchronous lookups that freeze the form.
What else is worth knowing about GlideAjax (async client-server)?
GlideAjax keeps forms responsive while still reaching real server data and logic.
Practise this on your own free instance.
Set up your free instance →
Already working on ServiceNow and stuck on a live ticket?Get an expert ServiceNow developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support