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

@Shivalika Input date is specific record updated 
input Duration as 3
both i am giving from Flow Designer

Ok @harinya 

 

I get it input date is a "GlideDateTime()" type field, so input duration is "3" - what ? What's the unit ? Just 3 integer ? 

 

Now I am sure it's breaking because comparison is not correct. 

 

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

 

Rajesh_Bhise
Tera Guru

Hello @harinya,

 

Please use the input variables as integer and date for duration and input date respectively. this will avoid one more line of code to skip parsing integer.

 

With this change, please use below script to achieve your goal.

 

(function execute(inputs, outputs) {
    // Get the current date and time
    var currentDateTime = new GlideDateTime();
gs.info('current date is' + currentDateTime );

    // Retrieve the input duration in months (e.g., 3 months)
    var inputDur = inputs.inputDuration; // Get the parsed integer input in this variable.
    gs.info('input duration is' + inputDur);

    // Retrieve the input date as per your expectations.
    var inputDate = new GlideDateTime(inputs.inputDate);

    // Calculate the comparison date (current date minus input duration in months)
    var comparisonDate = new GlideDateTime();
    comparisonDate.addMonthsLocalTime(-inputDur); // Negative means subtracting integer value of month from the current date.

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

    // Compare the input date to the calculated date
    if (inputDate >= comparisonDate) {
        outputs.flag = true; // if input date is less than new comparison date
    } else {
        outputs.flag = false; // if input date is greater than new comparison date
    }
})(inputs, outputs);