Flow designer Action script to last updated is less than 3 months

harinya
Tera Contributor

Hi 
i need to write script 

harinya_0-1744023908449.pngharinya_1-1744023951743.pngharinya_2-1744023989642.png

tried this but not working can someone please help
 it should not trigger the flow if last updated is less than 3 months

12 REPLIES 12

@harinya 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

HI @Ankur Bawiskar 
tried the script you have provide but getting NaN error, checking on that

@harinya 

did you add gs.info() and see?

(function execute(inputs, outputs) {
    // Get the current date and time
    var currentDateTime = new GlideDateTime();

    // Retrieve the input duration in months (e.g., 3 months)
    var inputDur = parseInt(inputs.inputDuration, 10); // Convert to integer

    gs.info('input duration is' + inputDur);
    // Retrieve the input date (last updated date)
    var inputDate = new GlideDateTime(inputs.inputDate);

    // Calculate the comparison date (current date minus input duration in months)
    var comparisonDate = new GlideDateTime();
    comparisonDate.addMonthsUTC(-inputDur);

    gs.info('comparison date is' + comparisonDate.getValue());

    // Compare the input date to the calculated date
    if (inputDate >= comparisonDate) {
        outputs.flag = true; // The record is updated within the last X months
    } else {
        outputs.flag = false; // The record is not updated within the last X months
    }
})(inputs, outputs);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@harinya 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Shivalika
Mega Sage

Hello @harinya 

 

I don't think you should be comparing like that. 

 

Use "getNumericValue()" to get the numeric value of both the glideDates, I think one is duration type of field, getNumericValue() should work there as well. 

 

Convert both into this milliseconds and then compare. You are comparing two completely different data types that's the reason.

 

Show me the input you are passing to this action. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY