How to reset GlideRecord object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2016 03:45 AM
Hello,
I have a code like this
var gr = new GlideRecord('myTable');
for(int i=0;i<5;i++){
gr.addQuery('column', i)
gr.query();
gr.getrowcount();
}
Problem is, for i=0 it works but for next iterator it appends the addQuery condition to previous one. Example
i=0 condition is column=0
i=1 condition is column=0^column=1
.
.
i=4 condition is column=0^column=1^column=2^column=3^column=4
My question is, how I can rest the gr after each loop, so that only one addQuery is added not the previous one?
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2016 03:47 AM
Add the new GlideRecord inside your for loop.
for(int i=0;i<5;i++){
var gr = new GlideRecord('myTable');
gr.addQuery('column', i)
gr.query();
gr.getrowcount();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2016 06:39 AM
Hi Chuck,
Thanks for your response!
In each loop if I create var gr = new GlideRecord('myTable'), will it not be create unnecessary objects?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2016 06:45 AM
No, because we haven't saved or committed anything. There is no call to gr.insert() or gr.update().
I also noted that both of us are using getRowCount() improperly (it's not all lower case) and we're not outputting anything. Try this.
for(int i=0;i<5;i++){
var gr = new GlideRecord('myTable');
gr.newRecord();
gr.addQuery('column', i)
gr.query();
gs.info(gr.getRowCount() + ' rows returned from query');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2016 06:53 AM
In actual logic I am going to update a column in the loop. Is it recommendable to use it?