logo

NJP

"addExtraField" amazing performance improvement to gliderecord

New article articles in ServiceNow Community · Dec 14, 2024 · article

Sometimes our GlideRecord queries include dotwalked fields from the table we're querying.

Each time we do this it adds significant load to the query.

This video will teach you how to use addExtraField in the GlideRecord API for a MASSIVE efficiency boost.

No copy/paste from docs here... The Duke gives you a full demo!

But don't take my word for it! Try it yourself. Here's the script!

var timerStart, timerEnd, queryRunTime, stringBuilder, queryOne, queryTwo; //START TIMER, RUN queryOne, DO SOMETHING WITH RESULTS timerStart = new Date().getTime(); // Record start time queryOne = new GlideRecord('incident'); queryOne.query(); while (queryOne.next()){ stringBuilder = queryOne.caller_id.name + " is part of " + queryOne.caller_id.company.name; } //FINISH TIMING ON FIRST SCRIPT AND OUTPUT RESULTS timerEnd = new Date().getTime(); // Record end time queryRunTime = timerEnd - timerStart; // Calculate execution time in milliseconds gs.print('QueryOne execution time: ' + queryRunTime + ' ms'); //RESTART TIMER, RUN queryTwo, DO SOMETHING WITH RESULTS timerStart = new Date().getTime(); queryTwo = new GlideRecord('incident'); queryTwo.addExtraField('caller_id.name'); queryTwo.addExtraField('caller_id.company.name'); queryTwo.query(); while (queryTwo.next()){ stringBuilder = queryTwo.caller_id.name + " is part of " + queryTwo.caller_id.company.name; } //FINISH TIMING ON SECOND SCRIPT AND OUTPUT RESULTS timerEnd = new Date().getTime(); // Record end time queryRunTime = timerEnd - timerStart; // gs.print('QueryTwo execution time: ' + queryRunTime + ' ms');

View original source

https://www.servicenow.com/community/developer-blog/quot-addextrafield-quot-amazing-performance-improvement-to/ba-p/3127640