IT CanvassTalk to an advisor
Development · LessonReviewed by Sneha I, ServiceNow Trainer, 8 yrs · Updated · Published · current release · intermediate

ServiceNow GlideAjax (async)

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

Quick answer

GlideAjax lets a ServiceNow client script ask the server a question, this user's manager or whether a value is unique, and receive the answer asynchronously, so the form never freezes. It has two halves: a client-callable Script Include extending AbstractAjaxProcessor, and the GlideAjax call from the client with parameters and a callback. The same method serves business rules and widgets.

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.

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