Current date/time to compare with end date/time minus 3 days

Vijay Baokar
Kilo Sage

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.

 

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
    //var diffdate = endDateTime - 3
    endDateTime.addDaysUTC(-3); //subtract 3 days with time from endDateTime

    var timediff = endDateTime;
    gs.log('TIME Diff IS :',timediff);
   
    gs.log('-3days',endDateTime);
    //if ( currentDateTime == timediff)
    if ( currentDateTime == timediff)
    {
        return 'yes';
    }

   
}
7 REPLIES 7

Mark Manders
Tera Patron

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';
}

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.

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; 
}

Hi @Ravi Gaurav  even now the wait for condition is still running and not moving ahead to run script activity.