Why You Should Not Use GlideRecord in ServiceNow Client Scripts
- nathanlee142
- Mar 20
- 3 min read
Updated: Mar 29

ServiceNow developers frequently utilize client scripts to provide dynamic and responsive interactions for users. A common question that arises is whether using GlideRecord within these scripts is considered good practice. This article clarifies the recommended approach to data retrieval in client scripts, explains why using GlideRecord in client-side scripting is generally discouraged, and outlines efficient, performance-friendly alternatives.
Understanding GlideRecord and Its Impact on Performance
GlideRecord is a powerful server-side object used to query and manipulate database records within ServiceNow. However, using GlideRecord directly in client-side scripts (like catalog client scripts or UI page client scripts) is not advisable and is often restricted, especially in scoped applications.
The primary reason to avoid using GlideRecord in client scripts is due to performance concerns. When you use GlideRecord client-side, the entire record—along with all its fields—is retrieved, even if you only require a single field. This unnecessary data retrieval can significantly degrade application performance and responsiveness, resulting in a suboptimal user experience.
Furthermore, starting with the Geneva release, ServiceNow began limiting the use of client-side GlideRecord in scoped applications to enforce better scripting practices and optimize platform performance.
Recommended Alternatives to GlideRecord in Client Scripts
To efficiently handle server data in client scripts, ServiceNow recommends two primary alternatives:
1. GlideAjax
GlideAjax allows client-side scripts to retrieve server-side data asynchronously. Unlike GlideRecord, GlideAjax requests only the necessary data fields from the server, drastically improving performance.
Example of using GlideAjax:
Client-side
function getManagerName() {
var ga = new GlideAjax('UserUtils');
// Example script include name
ga.addParam('sysparm_name', 'getManagerName');
ga.addParam('sysparm_user_id', g_form.getValue('user_field'));
// Use user field value
ga.getXMLAnswer(function(answer) {
if (answer && answer !== 'null') { // Ensure answer is valid
g_form.setValue('manager_field', answer);
} else {
if (g_form.getControl('manager_field')) {
// Check if field exists
g_form.showFieldMsg('manager_field', 'Failed to retrieve manager information.', 'error');
}
}
});
}
Server-side (Script Include - UserUtils)
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, { getManagerName: function() {
var userId = this.getParameter('sysparm_user_id');
var user = new GlideRecord('sys_user');
if (user.get(userId)) {
return user.manager.getDisplayValue();
}
return null;
},
type: 'UserUtils'
});
Practical Use Case:
Fetching a user's manager name to populate a form dynamically.
Retrieving specific details from related records without loading entire records.
2. g_scratchpad
The g_scratchpad object is another excellent alternative, suitable for scenarios where data required by the client is known at the time of form loading. This method pushes necessary information from server-side display business rules directly into the client environment during form initialization.
Example of using g_scratchpad:
Server-side (Business Rule - Display):
g_scratchpad.managerName = current.manager.getDisplayValue();
Client-side (Client Script):
var managerName = g_scratchpad.managerName;
g_form.setValue('manager_field', managerName);
Practical Use Case:
Populating form fields with default data at form load without additional server requests.
Alternative Practices to Consider
While GlideAjax and g_scratchpad are the most common alternatives, another method like g_form.getReference() can retrieve reference fields dynamically. While g_form.getReference() can retrieve reference field data dynamically, it loads all fields by default, which may impact performance. However, it is still a viable option for retrieving specific reference field values when used correctly. ServiceNow experts often recommend GlideAjax or g_scratchpad for better efficiency, especially in scoped applications.
Example of using g_form.getReference():
g_form.getReference('manager', function(ref) {
if (ref) {
g_form.setValue('manager_name', ref.name);
}
});
Conclusion
Using GlideRecord in ServiceNow client scripts should be avoided due to significant performance impacts and the restrictions in scoped applications. Instead, leverage GlideAjax for dynamic server interactions or utilize g_scratchpad when preloaded data suffices. Adopting these best practices ensures efficient data handling, improved performance, and a smoother experience for end users.
Actionable Next Steps
Review your existing client scripts to identify any usage of GlideRecord.
Refactor scripts using GlideRecord to GlideAjax or g_scratchpad for optimal performance.
Educate your development team about best practices for client-side scripting in ServiceNow to avoid future performance issues.