Brad Bowman
Kilo Patron
Kilo Patron

The addExtraField method that was added to the GlideRecord API in a recent release can drastically improve GlideRecord execution times.  Here is a real life example of just such a case.

Background:

We recently encountered performance issues while developing our incident form / submission process.  We have three mandatory fields - Service (business_service), Service offering, and Configuration item.  Each reference field should only show records that are relevant based on the other two selections, but the fields can be populated in any order. 

The Issue:

When selecting a record in each field, the typeahead and reference search was prohibitively slow - locking up the session/node while the results were being retrieved.  Each field has a reference qualifier that calls the same Script Include, passing in the value of the other two fields.  The Script Include runs a series of GlideRecord queries in different functions to filter the list appropriately.  Breaking down each GlideRecord, we discovered one that is dot-walking on the returned records to push a value to an array.

A Solution:

By simply using addExtraField the performance issues were remediated, with each reference search instantaneously showing the filtered results as each field value changed.  

An Example:

In this extremely simplified example, I am querying my cmdb_ci_service table which has 13K records.  I need to add the name field from each record's parent to an array.

Here is the very basic GlideRecord, isolated for demonstration purposes and executed in a Fix Script:

var parArr = [];
var ciGr = new GlideRecord('cmdb_ci_service');
ciGr.query();
while (ciGr.next()) {
    parArr.push(ciGr.parent.name);
}

 

This simple query is taking about 5 seconds to execute as the parent record for each GR result must be returned in order to retrieve the name field.

 

BradBowman_0-1757595685807.png

 

When using addExtraField prior to the query execution, the GlideRecord retrieves the name field from the parent record while retrieving the entire service record, resulting in a processing time that is reduced by an astounding 73% in this case! 

 

var parArr = [];
var ciGr = new GlideRecord('cmdb_ci_service');
ciGr.addExtraField("parent.name"); 
ciGr.query();
while (ciGr.next()) {
    parArr.push(ciGr.parent.name);
}

BradBowman_1-1757596678605.png

 

 

Version history
Last update:
6 hours ago
Updated by:
Contributors