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

oh im sorry im taking my words back. I miss understood the question.


What Anurag propose that can work in your case.


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

Hi Anurag,



you hit the nail , thanks a lot, this is exactly what I was looking for.



By the way, really strange name of the function and I don't understand why it isn't a part of official GlideRecord documentation on wiki 😕


i know, its not documented properly also, you wont it on wiki also.


-Anurag

Holy cow is THIS some hard to find knowledge!?!?! Thank you for posting it.

 

Working on a Scripted REST, and I'm like, "How the heck do I return paged chunks of data?" There's literally zero in any of the REST docs or even Glide. If you search for "offset," which is the common way to talk about it, you can't find a solution, anywhere. We need to get this tagged to a few other use cases in the documentation ... for real.