
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:02 AM - edited 12-20-2023 10:04 AM
Hey Everyone,
I'm super new with the date/time fields in SNOW. Basically I want to compare two date/time field values that have the same sys_id for a task.
Below is my code for right now.
var incTask = new GlideRecord("task_sla");
incTask.addQuery("task", "task.sys_id");// task.sys_id
incTask.addQuery("has_breached", true);
incTask.query();
incTask.query();
while(incTask.next()){
gs.info("This is the incident number: " + incTask.task.getDisplayValue());
gs.info("This is the breach times: " + incTask.planned_end_time.getDisplayValue());//breach time column
}
What is happening, I'm getting two values for the same task.sys_id for the breach time column. What I want to do is compare those times and choose the earliest/soonest time to breach. This is where I get a little stuff. Does anyone have any suggestions?
This is my log output:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:38 AM
@Community Alums : Please try the below code.
var incTask = new GlideRecord("task_sla");
incTask.addQuery("task", "PASTE_YOUR_SYS_ID_HERE");
incTask.addQuery("has_breached", true);
incTask.orderBy("planned_end_time"); // Sorting in Ascending order
incTask.query();
if (incTask.next()) { // Returning only first record
gs.info("This is the incident number: " + incTask.task.getDisplayValue());
gs.info("This is the breach times: " + incTask.planned_end_time.getDisplayValue()); //breach time column
}
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 10:38 AM
@Community Alums : Please try the below code.
var incTask = new GlideRecord("task_sla");
incTask.addQuery("task", "PASTE_YOUR_SYS_ID_HERE");
incTask.addQuery("has_breached", true);
incTask.orderBy("planned_end_time"); // Sorting in Ascending order
incTask.query();
if (incTask.next()) { // Returning only first record
gs.info("This is the incident number: " + incTask.task.getDisplayValue());
gs.info("This is the breach times: " + incTask.planned_end_time.getDisplayValue()); //breach time column
}
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 11:23 AM
Hey!
This is super helpful, but I still need both values. I need to get the earliest time between the both. I just didn't know how I could get both values and compare.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 11:33 AM - edited 12-20-2023 11:33 AM
@Community Alums : Will there be only two records all the time to compare ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 12:55 PM
No, sometimes, it could be more. I was just using that as a test to see if I could do it.