- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 07:16 AM
Hello,
I have a background script that I need to be able to sort records by state. My state has several choices: Pending, Verified, Cancelled, Expired. The way this needs to be sorted is by most recently updated and pending state. All pending records should show first, but the states need to be grouped.
This is what I have so far:
var gr = new GlideRecord('u_custom_table');
gr.addQuery('active=true');
gr.groupBy('u_status');
gr.orderByDesc('u_status');
gr.orderByDesc('sys_updated');
gr.query();
while(gr.next()) {
gs.print('u_number' + ' Updated on ' + gr.sys_updated + ' Status: ' + gr.u_status);
}
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 07:30 AM
Hi,
Simple fix for this. You need to use GlideAggregate for the groupBy method.
var agg = new GlideAggregate('incident');
agg.groupBy('state');
agg.orderByDesc('sys_updated');
agg.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 07:28 AM
Hi,
Try this:
var gr = new GlideRecord('u_custom_table');
gr.addQuery('active=true');
gr.orderBy('u_status');
gr.setLimit(20);
gr.query();
while (gr.next()) {
gs.print('Number: ' + gr.getValue('u_number') + ' Updated on: ' + gr.getDisplayValue('sys_updated') + 'Status: ' + gr.getDisplayValue('u_status'));
}
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 06:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 07:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 06:21 AM