How to get filter based on time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 04:54 AM
Hi Everyone,
How to get filter based on time? ex. Need cases created between yesterday 8pm to today 8pm.
Can anyone help me on this.
Thanks in advance..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 05:24 AM
Hi @lucky6,
You can use the sys_created_on field to filter cases based on their creation time. Here's an example of how to filter cases created between yesterday 8 PM and today 8 PM:
var start = new GlideDateTime();
start.setDayBefore(1);
start.setHourOfDay(20);
start.setMinute(0);
start.setSecond(0);
var end = new GlideDateTime();
end.setHourOfDay(20);
end.setMinute(0);
end.setSecond(0);
var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '>=', start);
gr.addQuery('sys_created_on', '<=', end);
gr.query();
while (gr.next()) {
// Do something with the filtered incidents
}
This script creates two GlideDateTime objects, start and end, and sets them to yesterday 8 PM and today 8 PM respectively. Then it creates a GlideRecord object for the incident table, adds the sys_created_on queries to filter the records, and runs the query. Finally, it loops through the filtered records using gr.next() and performs some action on each record.
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 12:18 AM
Thanks for the reply..
when I added this script in rest api I am getting 500 error with cannot find function setDayBefore function in object.
Any idea on this..