Compare Date date/time fields with same sys_id

Community Alums
Not applicable

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: 

904.PNG

1 ACCEPTED SOLUTION

Sainath N
Mega Sage
Mega Sage

@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.

View solution in original post

8 REPLIES 8

Sainath N
Mega Sage
Mega Sage

@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.

Community Alums
Not applicable

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.

@Community Alums : Will there be only two records all the time to compare ?

Community Alums
Not applicable

No, sometimes, it could be more. I was just using that as a test to see if I could do it.