Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

RefFieldFetcher — One Script Include to Replace All Your GlideAjax Endpoints (Free Update Set)

dhravesh
Tera Contributor

Hi everyone,

I built RefFieldFetcher to solve a problem I've seen on every ServiceNow project — developers creating dozens of nearly-identical Script Includes just to do async reference lookups via GlideAjax.

THE PROBLEM:
• g_form.getReference() and getXMLWait() are synchronous — they freeze the form
• Teams create a new Script Include for every GlideAjax use case
• 50 developers × 3 years = unmaintainable Script Include sprawl with inconsistent security

THE SOLUTION:
RefFieldFetcher is a single, client-callable Script Include that handles all async reference field lookups. Pass it a table, sys_id(s), and fields — it returns structured JSON.

FEATURES:
• Dot-walk support — fetch caller_id.department.name in one call
• Three return modes — value, display, or both
• Encoded query support — not just sys_id lookups
• 7-layer security — table allowlist, field denylist, ACL enforcement, dot-depth limits, encrypted type blocking, encoded query validation, admin-only ACL bypass
• 9 system properties — configure everything without touching code
• User-scoped caching with configurable TTL
• Server-side direct call via getFieldsDirect()

BEFORE (synchronous):
var rec = g_form.getReference('caller_id'); // FREEZES THE FORM
g_form.setValue('location', rec.location);

AFTER (async with RefFieldFetcher):
var ga = new GlideAjax('RefFieldFetcher');
ga.addParam('sysparm_name', 'getFields');
ga.addParam('sysparm_table', 'sys_user');
ga.addParam('sysparm_sys_ids', newValue);
ga.addParam('sysparm_fields', 'name,email,location.name');
ga.addParam('sysparm_mode', 'display');
ga.getXMLAnswer(function(answer) {
var data = JSON.parse(answer);
if (data.rows && data.rows.length) {
g_form.setValue('location', data.rows[0]['location.name']);
}
});

Same result. Zero form freeze. Zero new Script Includes.

DOWNLOAD & FULL DOCUMENTATION:
GitHub: https://github.com/dhravesh07/servicenow-solutions/tree/main/RefFieldFetcher

The Update Set XML contains 1 Script Include + 9 System Properties. Import via Retrieved Update Sets > Import Update Set from XML.

Tested on Washington DC, Vancouver, and Utah. Global scope, no dependencies.

Would love to hear feedback or if anyone has similar patterns they've solved differently!

0 REPLIES 0