how to use setLimit I have total record as 30 and i want the records to be stored in batches
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2023 06:17 PM
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
thanks everyone
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2023 06:41 PM
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());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2023 07:00 PM
geting offset error? @Chaitanya Redd1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2023 07:23 PM
Can you share error?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2023 07:26 PM