Date Comparison in Flow designer

shivani42
Tera Contributor

Hi All,

I have a requirenment where i need to create a flow on Manage token table where i need to compare the record where the type is refresh token and then i will create a flow which create an incident automatically when the record has expire value <= 15 days.

For exmaple, if a record microsoft with type refresh token has expire field value as NOV 26, 2024 then flow should trigger and create an incident saying the Oauth token for Microsoft is getting expired in 15 days.

The comparison would achieve with scripting only. I am not able to figure out where this script should be used in Flow.

Script---

var dateField = new GlideDateTime(current.getValue('expires'));

var nowTime = new GlideDateTime();

var dur = new GlideDuration();

dur = GlideDateTime.subtract(nowTime, dateField);
var days = dur.getDayPart();
if(days <= 15){
    gs.info("alert");
}
}
3 REPLIES 3

Hitoshi Ozawa
Giga Sage
Giga Sage

Since you haven't provided a complete flow, it's difficult to answer but one way is to create an Action that return True/False based on the if condition. Call this Action from the flow and have an if condition based on the returned value.

Gangadhar Ravi
Giga Sage
Giga Sage

@shivani42 Please check this article. 

 

https://www.servicenow.com/community/developer-articles/date-difference-in-flow-designer/ta-p/229620...

Please mark my answer correct and helpful if this works for you.

 

Tai Vu
Kilo Patron
Kilo Patron

Hi @shivani42 

You can easily query Token records that are set to expire in 15 days using Lookup Records and Condition Builder, so there’s no need to write any code!

Here’s a quick sample configuration for reference.

Timi_0-1730177560425.png

 

Then loop through each records about to expire and generate according incidents.

 

Cheers,

Tai Vu