How to GlideRecord a Table along with giving Pagination details and Orderby values as Queryparams.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 03:22 AM
I need to Query a Table Using Gliderecord functionality, along with giving pagination details.
while querying, I need it to be sorted by a choice field's Label (the choice field which resides within the table).
I have tried orderBy(), sortBy(), chooseWindow(), setLimit(), setOffset(), setStart().
Is there any other way to do this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 04:44 AM
var queryObjectString;
var poolObject = new GlideRecord('u_m2m_data'); // u_m2m_data is a table which maps the pool table('u_pool') and object table('u_object') records
queryObjectString = 'u_pool.u_numberIN' + pool_list;
if (Status1 != 'null')
queryObjectString = queryObjectString + '^u_object.install_statusIN' + Status1;
if (order_by == "object_ID") { // where u_object_id is an integer field
if (sort_by == "ASC")
poolObject.orderBy('u_object.u_object_id');
else
poolObject.orderByDesc('u_object.u_object_id');
}
var total = Sysparam_limit + Sysparam_offset;
poolObject.chooseWindow(Sysparam_offset, total);
'
poolObject.query();
similar to "orderby using object_id", I need to do orderby the records using a choice field's ('u_object.install_status') label.
this field is defined under 'u_object' table.
but we gliderecord through the M2M table to get the details from both pool table & object table.
How can we do this !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 04:42 PM
Hi @Athuldas S ,
Give this a try:
var gr = new GlideRecord("incident");
gr.addQuery('field_name', 'value');
// Set the order by the choice field's label
gr.orderBy('choice_field_name');
// Set the limit and offset for pagination
var itemsPerPage = 10;
var pageNumber = 1;
var start = (pageNumber - 1) * itemsPerPage;
gr.setLimit(itemsPerPage);
gr.setStart(start);
gr.query();
while (gr.next()) {
// Add your logic here
}