how to use setLimit I have total record as 30 and i want the records to be stored in batches

Santosh Oraon
Tera Expert

hello everyone ,I have requirement that..

how to use setLimit I have total record as 30 and i want the records to be stored in batches like if Batch =10 , then first 10 records are stored in my final array then , next 10 then, next 10 like that .

I am writing this script but only first 10 records are stored , i want in batches 

SantoshOraon_0-1683249304884.png

thanks everyone

.

5 REPLIES 5

Chaitanya Redd1
Tera Guru

Hi,
Try below code and let me know if you still find any error.

 

var batch = 10;
var final_arr = [];
var gr = new GlideRecord('incident');
gr.addEncodedQuery();
gr.orderBy('sys_created_on'); // Replace sys_created_on with the field you want to sort by
var total_records = gr.getRowCount();
var batches = Math.ceil(total_records/batch);
for (var i = 0; i < batches; i++) {
  gr.setLimit(batch);
  gr.setOffset(i * batch);
  gr.query();
  while (gr.next()) {
    final_arr.push(gr.number.toString());
  }
}

 

SantoshOraon_1-1683251987492.png

geting offset error? @Chaitanya Redd1 

Can you share error?

Santosh Oraon
Tera Expert