ServiceNow Learning 48: Usage of restoreLocation() function in GlideRecord in ServiceNow.

Shamma Negi
Kilo Sage
Kilo Sage

Hi All,

 

I found a very useful way to use restoreLocation() in GlideRecord scripting.

 

Script:

 

var incidentRecords = new GlideRecord('incident');
incidentRecords.addActiveQuery(); // same as .addQuery('active', true) but fancier 🙂
incidentRecords.setLimit(10); // did you know you could grab just the first x-number of records?
incidentRecords.orderBy('number'); // order ascending
incidentRecords.query();

// print off the first 10 incident numbers
while (incidentRecords.next()) {
gs.info('Incident number: {0}', incidentRecords.number);
}

// print off the 10th one again, we are still at the end
gs.info('Current Incident number: {0}', incidentRecords.number);

// reset the pointer to beginning (before the first record)
incidentRecords.restoreLocation();

// print off the first 10 incident numbers starting with the first
while (incidentRecords.next()) {
gs.info('Incident number: {0}', incidentRecords.number);
}

 

Hope it helps you.

I hope this article helpful. Please mark it as helpful and bookmark if you like it.

 

Regards,

Shamma

 

Regards,Shamma Negi
0 REPLIES 0