Using sysparm_offset in REST API Script

ericeger
Tera Guru

Hi everyone,

I've created a REST API Script that allows me to get records from my incident table.   However, we would like to use pagination so that if we have a multitude of records, we are able to page through and not have a massive amount of data in one call.   From what I've been finding, using a combination of sysparm_limit and sysparm_offset is the best way to go to have something that is similar to pagination.   Since I'm using a script instead of the REST API Explorer to create my objects, I haven't been able to find anything that allows to use something similar to sysparm_offset. The script I have set up creates the JSON object since I have to do calls into multiple tables to get certain values.   To substitute sysparm_limit, I found that I can use gr.setLimit(10000) as an example since that's part of the glide record functionality.   There was a previous post that had said about using gr.Window(10, 20) or something along those lines, I'm not 100% sure.   I know that I can get sysparm_offset as a queryParam, but what to do with it from there, I'm not sure.   If someone could point me in the right direction, that would be great! Thanks!

Eric

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Eric,



I couldn't find it in the documentation, but other community articles seem to point to this solution.



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


View solution in original post

6 REPLIES 6

ibhavya
Tera Contributor

Thank you! It was helpful 🙂

vi1
Kilo Explorer

Hi Eric,

 

did you had to create query parameters by going to system web service> scripted REST API>query parameters ? to use the variables  you mentioned above?

var offset = request.queryParams.offset,
     limit = request.queryParams.limit,