GlideAjax: call the server from a client script
The standard, asynchronous way to fetch server data from a form: a client-callable Script Include plus a client script that never freezes the browser.
October 1, 2026 · #glideajax #client-script #script-include
When a form needs data the browser doesn’t have, use GlideAjax. It keeps logic and security on the server, and the asynchronous call keeps the form responsive.
// 1. Script Include "UserInfoAjax", with "Client callable" checked
var UserInfoAjax = Class.create();
UserInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManagerName: function () {
var userId = this.getParameter('sysparm_user');
var user = new GlideRecord('sys_user');
if (!userId || !user.get(userId)) return '';
return user.getDisplayValue('manager');
},
type: 'UserInfoAjax',
});
// 2. onChange client script on the caller field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) return;
var ga = new GlideAjax('UserInfoAjax');
ga.addParam('sysparm_name', 'getManagerName');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function (managerName) {
g_form.addInfoMessage(managerName ? 'Manager: ' + managerName : 'No manager on record');
});
}
How it works
sysparm_nameselects the Script Include method; othersysparm_parameters carry your inputs.getXMLAnswer()is asynchronous and hands the return value straight to the callback.
Gotchas
- Avoid
getXMLWait(): it freezes the browser and isn’t available in Service Portal. - Client-callable methods can be invoked by any logged-in user. Check permissions inside the method if the data is sensitive.
MIT licence. Provided as-is, without warranty. Test in a sub-production instance first.