Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to get records using sysparm_limit and sysparm_offset in Scripted REST API

lucky6
Tera Contributor

Hi everyone,

I have created scripted rest api to get case records from my case table and here i am unable to get records using sysparm_limit and sysparm_offset query parameters.

I have more than 100k records in table to send third party team everyday,...is anyone has any idea how to achieve this through sysparm_limit and sysparm_offset in rest API.

 

I have seen few community links related to gr.choosewindow(10,0) but i am not sure how it works. can anyone provide solution for this?..Thanks

 

1 REPLY 1

lucky6
Tera Contributor

Please find the below script which i have tried.

 

 var answer = {};
        var limit = request.queryParams.sysparm_limit;
        var offset = request.queryParams.sysparm_offset;
            array = [],
            var gr = new GlideRecord('sn_customerservice_case);
        gr.addEncodedQuery('active=true');
        gr.orderByDesc('sys_created_on');
        gr.chooseWindow(offset, offset+ limit);
        gr.query();
        while (gr.next()) {
            var fields = {};
            var totalcount = gr.getRowCount();
            fields.Number = gr.number.toString();
            fields.short_description = gr.short_description.toString();
            array.push(fields);
        }
 
Request:
sysparm_limit = 3
sysparm_offset = 3