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

Ankur Bawiskar
Tera Patron
Tera Patron

@harinya 

share that script here and not image.

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
Tera Contributor

(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

// Retrieve the input date (last updated date)
var inputDate = new GlideDateTime(inputs.inputDate);


// Compare the input date to the calculated date
if (inputDate < comparisonDate) {
outputs.flag = currentDateTime; // 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);

@harinya 

try this

(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

    // 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);

    // 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 

Did you try the script I shared above?

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