Current date/time to compare with end date/time minus 3 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 10:26 PM
Hi Folks,
I have below script in wait for condition activity of wf, where i need to check if currentDateTime == endDateTime - 3 days
Suppose "current.variables.end" is 2024-08-30 10:30:00
current date/time is 2024-08-26 10:30:00
result: This script should trigger next activity when current datetime reaches 2024-08-27 10:30:00 , that is 3 days minus 2024-08-30 10:30:00, BUT ITS NOT WORKING, Please suggest the correction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 12:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 12:55 AM - edited 08-26-2024 12:57 AM
Hi @Ravi Gaurav Please check this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:00 AM
That's strange..
I did more changes and hit and trail.. use the below
function ifScript() {
var currentDateTime = new GlideDateTime();
var endDateTime = new GlideDateTime(current.variables.end);
endDateTime.addDaysUTC(-3);
gs.log('Current DateTime: ' + currentDateTime.getDisplayValue());
gs.log('End DateTime minus 3 days: ' + endDateTime.getDisplayValue());
var tolerance = 60 * 1000;
var timeDiff = Math.abs(currentDateTime.getNumericValue() - endDateTime.getNumericValue());
if (timeDiff <= tolerance) {
return true;
}
return false;
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/