Sort by based on time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 03:49 AM
Hi all,
I need to sort queried record based on time in update filed instated of date .
i have tried the below code it is sorting based on date.
var prob = new GlideRecord('problem');
query = "sys_updatedBETWEENjavascript:gs.dateGenerate('" + startDate.getLocalDate() + "','00:00:00')@javascript:gs.dateGenerate('" + endDate.getLocalDate() + "','23:59:59')";
prob.addEncodedQuery(query);
prob.orderBy('sys_updated');
prob.query();
Is there any way to do this
Can anyone help me on this
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 03:57 AM
Hello Pavithra,
prob.orderBy('sys_updated'); is not correct, it should be sys_updated_on
Further more, prob.orderBy('sys_updated_on.time'); will sort it using the time however as I am not entirely sure about the use case, kindly check the data once sorted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 03:58 AM - edited 06-07-2023 04:01 AM
@Community Alums
This can help !
make sure to update the colon ':'
var prob = new GlideRecord('problem');
var query = "sys_updatedBETWEENjavascript:gs.dateGenerate('" + startDate.getLocalDate() + "','00:00:00')@javascript:gs.dateGenerate('" + endDate.getLocalDate() + "','23:59:59')";
prob.addEncodedQuery(query);
prob.orderBy('sys_updated_time'); // Sort by the time portion of the sys_updated field
prob.query();
In the code above, I added the orderBy
function to sort the records based on the time portion of the sys_updated
field. To achieve this, you can use a field named sys_updated_time
(assuming it exists in your table), which represents the time part of the sys_updated
field.
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 03:58 AM
Hi @Community Alums
var prob = new GlideRecord('problem');
query = "sys_updatedBETWEENjavascript:gs.dateGenerate('" + startDate.getLocalDate() + "','00:00:00')@javascript:gs.dateGenerate('" + endDate.getLocalDate() + "','23:59:59')";
prob.addEncodedQuery(query);
prob.orderBy('sys_updated_on');
prob.query();
while(prob.next()){
gs.print(prob.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 04:07 AM
Hi @Manmohan K ,
I given the filed name correctly in my instance but while posting the question i given filed name incorrectly .
my question is I need to sort based on time par only in sys_updated_on filed if I use below code it is sorting based on date filed
prob.orderBy('sys_updated_on');
Thanks