Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to go back to the first record for GlideRecord

PhoenixMing0912
Giga Expert

Hi all,

I am using GlideRecord like:

How to go back to the first record for GlideRecord:

var gr_incident = new GlideRecord("incident");
gr_incident.addQuery("xxx");
gr_incident.query();

while(gr_incident.next()) {

}

After the loop, I want to loop the gr_incident from the beginning again, but I don't want to query the db again, is it possible to do that?

6 REPLIES 6

Thanks @Gabriel Cabral for pointing this out. You are right. It doesn't work.

I tried running this script in my PDI and what you are pointing out is correct.

 

Is there a way we can achieve? 

 

Thanks, and Regards,

Mahesh Kumar

I think that most simple way is using GlideQuery:

 

var incidentArray = new GlideQuery('incident')
    .where('active', true)
    .select('number', 'short_description', 'state', 'state$DISPLAY')
    .toArray(1000);