ServiceNow GlideAjax cheat sheet
GlideAjax calls a client-callable script include from the browser and gets an answer back, without loading whole records into the form.
Server and client6 methods · examples checked with the Script Checker · reviewed October 2026
Client-callable script include
# Extend AbstractAjaxProcessor, tick Client callable, read parameters with this.getParameter() and return a string.
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getManager: function() {
var user = new GlideRecordSecure('sys_user');
if (!user.get(this.getParameter('sysparm_user'))) return '';
return user.getValue('manager');
},
type: 'UserUtils'
});
Do not override initialize(), and use GlideRecordSecure so ACLs apply.
new GlideAjax('ScriptInclude') + getXMLAnswer()
# Calls the method named in sysparm_name and receives the answer in a callback.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'getManager');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(answer) {
g_form.setValue('u_manager', answer);
});
}
Every parameter name must start with sysparm_; others arrive empty.
Returning several values as JSON
# GlideAjax answers are strings, so return JSON.stringify() from the script include.
var UserInfo = Class.create();
UserInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserInfo: function() {
var user = new GlideRecordSecure('sys_user');
if (!user.get(this.getParameter('sysparm_user'))) return '';
return JSON.stringify({
email: user.getValue('email'),
phone: user.getValue('phone')
});
},
type: 'UserInfo'
});
JSON.parse(answer) in the client
# Turns the JSON answer back into an object in the client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('UserInfo');
ga.addParam('sysparm_name', 'getUserInfo');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(answer) {
if (!answer) return;
var info = JSON.parse(answer);
g_form.setValue('u_email', info.email);
g_form.setValue('u_phone', info.phone);
});
}
Older form: the answer is an attribute of the response XML.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'getManager');
ga.addParam('sysparm_user', newValue);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('u_manager', answer);
});
}
getXMLAnswer() does the same with less code.
Avoid: shown so you recognise it
Waits for the answer synchronously.
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'getManager');
ga.getXMLWait();
var answer = ga.getAnswer();
It freezes the browser and is not supported in Service Portal. Use getXMLAnswer() with a callback.
Frequently asked questions
Why is my GlideAjax parameter empty in the script include?
GlideAjax only sends parameters whose names start with sysparm_. Rename it (for example sysparm_user) on both sides.
Why does my GlideAjax answer say [object Object]?
The answer is always a string. Return JSON.stringify(result) from the script include and JSON.parse(answer) it in the client.