How to compare two date/time fields?

Admin7267
Kilo Sage

I have a requirement in Change Request that is if the Planned end date is less than the Actual end date then I need to trigger notification. How to compare the two date/time fields?

2 ACCEPTED SOLUTIONS

yad_achyut
Giga Guru

@Admin7267 : you can use Client Script of type onSubmit with the following code:

var plannedDate = new GlideDateTime(current.planned_end_date);
var actualDate = new GlideDateTime(current.actual_end_date);
if (plannedDate.before(actualDate))
{
gs.addInfoMessage("Planned End Date is before Actual End Date.");
}

inplace of gs.addInfoMessage you can use a logic to trigger your notification.

View solution in original post

Admin7267
Kilo Sage
var plannedEnd = new GlideDateTime(current.end_date);
var actualEnd = new GlideDateTime(current.work_end);
 
if (actualEnd.after(plannedEnd)) {
gs.eventQueue();
}

View solution in original post

4 REPLIES 4

Viraj Hudlikar
Tera Sage
Tera Sage

Hello @Admin7267 

 

In your question there are so many open questions like: 

1) When you want this action to be performed?

2) Are you thinking for all CHG records?

3) Do you want this only when record is getting updated?

 

To compare the Planned end date and Actual end date in a Change Request and trigger a notification if the Planned end date is less than the Actual end date, you can use a Business Rule.

 

In case if you are looking only for validation of two fields when it's entered then you can write Ui Policy and compare each other.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Admin7267 

 

Try this way

 

AGLearnNGrow_0-1737711457012.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

yad_achyut
Giga Guru

@Admin7267 : you can use Client Script of type onSubmit with the following code:

var plannedDate = new GlideDateTime(current.planned_end_date);
var actualDate = new GlideDateTime(current.actual_end_date);
if (plannedDate.before(actualDate))
{
gs.addInfoMessage("Planned End Date is before Actual End Date.");
}

inplace of gs.addInfoMessage you can use a logic to trigger your notification.

Admin7267
Kilo Sage
var plannedEnd = new GlideDateTime(current.end_date);
var actualEnd = new GlideDateTime(current.work_end);
 
if (actualEnd.after(plannedEnd)) {
gs.eventQueue();
}