Set offset for GlideRecord query

peter_repan
Tera Guru

Hi all,

I would like to create a custom table with pagination. I need to fill table with GlideRecord query.

I know that it is possible to use setLimit(int) function to get only requested number of rows, but it is somehow possible to set offset of this records, to be able to use pagination for fetching second, third... set of items ?

Example:

var gr = new GlideRecord('incident');

gr.skip(30); ----> how to do something like this ?

gr.setLimit(10);

gr.query();

1, 2, 3, 4, 5

---> will return fourth set of 10 records

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi Peter,



I think this is what you are looking for



gr.chooseWindow(10, 20);       // this will give you 10 records, starting form the 11th to 20th.



Real more here in depth


GlideRecord Glimmerings: Windows...


-Anurag

View solution in original post

16 REPLIES 16

Hi Zack,

 

Yes this was kind of a hidden thing back the days but I'm surprised it still is. Here are some good links to read about this

GlideRecord Query Cheat Sheet - ServiceNow Guru

SN Pro Tips — GlideRecord Pagination - Page through your GlideRecord query

 

 

-Anurag

I'm coming up on 8 years, here, so ... if I have learned anything in that time, it is that we are fantastic at hiding good features. ðŸ˜‡

 

Again, thanks much for your community participation! Community is my "final stop" for searches, and finding the top match was from 2015 did not excite me, today, to say the least. I left feedback for several of our documentation pages ... rather agitated feedback ...

 

Especially this page which outlines how to stream data from a Scripted REST, and it even shows a "limit" function, but no "offset." If you are trying to stream using this technique, it cuts the table short at 100 records because it doesn't understand the next piece it has to do ...