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-25-2024 11:01 PM
Can you try this:
answer = ifScript();
function ifScript() {
var currentDateTime = new GlideDateTime(); // Gets the current date and time
var endDateTime = new GlideDateTime(current.variables.end); // Gets the end date and time from the variable
// Subtract 3 days from the endDateTime
endDateTime.addDaysUTC(-3);
// Log the current and endDateTime for debugging
gs.log('Current DateTime: ' + currentDateTime.getDisplayValue());
gs.log('End DateTime minus 3 days: ' + endDateTime.getDisplayValue());
// Compare the two times using getDisplayValue()
if (currentDateTime.getDisplayValue() == endDateTime.getDisplayValue()) {
return 'yes';
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 12:14 AM
Hi @Mark Manders Thanks for your response with your code i am getting datetime value but wait for condition activity is not moving ahead for next action. Now my current date/time is matching with End date/time after -3 days logic but wait for condition is still running.
if the condition is met then it should move to next activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 12:21 AM
Hi @Vijay Baokar
can you use the below script to address your issue
answer = ifScript();
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());
if (currentDateTime.getValue() == endDateTime.getValue()) {
return true; // Returning true for the Wait for Condition to move forward
}
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 12:48 AM
Hi @Ravi Gaurav even now the wait for condition is still running and not moving ahead to run script activity.