Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

How to compare Expiry Date with Today Date in a Custom Action and return Boolean value?

pusalagc
Tera Contributor

Hi Community,

I am working on a requirement in ServiceNow HR scope (Human Resources: Core) using Flow Designer.

I need to create a Custom Action that accepts an Expiry Date as an input and returns a Boolean value based on whether the date has expired.

Requirement:

I will pass an Expiry Date, which is a Date field, to the Custom Action.

The Custom Action should compare the Expiry Date with today's date.

Expected result:

  1. If Expiry Date is before today, return TRUE.

  2. If Expiry Date is today, return FALSE.

  3. If Expiry Date is after today, return FALSE.

For example, if today is 16-08-2026:

Expiry Date: 14-08-2026
Expected result: TRUE

Expiry Date: 15-08-2026
Expected result: TRUE

Expiry Date: 16-08-2026
Expected result: FALSE

Expiry Date: 17-08-2026
Expected result: FALSE

Expiry Date: 20-08-2026
Expected result: FALSE

Custom Action Input:

Name: expiry_date
Type: Date

Custom Action Output:

Name: is_expired
Type: True/False

I need the recommended ServiceNow script for the Custom Action to compare the input Expiry Date with today's date and return the Boolean value.

Since this Custom Action is being created in the Human Resources: Core scope, is there anything specific I should consider when comparing the dates?

Please provide the correct approach or script.

Thank you.

1 REPLY 1

Juhi Poddar
Kilo Patron

Hello @pusalagc 

 

Here are the steps you can follow:

1. Create the input for your Flow Action

  • Configure the input as a Date field and name it expiry_date.

JuhiPoddar_2-1786952373687.png

 

2. Add a Script step

JuhiPoddar_4-1786952530720.png

  • Use the following script:
(function execute(inputs, outputs) {
    var expiryDate = new GlideDate();
    expiryDate.setValue(inputs.expiry_date + "");
    var today = new GlideDate();
    outputs.is_expired = expiryDate.getValue() < today.getValue() ? 1 : 0;
})(inputs, outputs);

3. Configure the output

Create a True/False output named is_expired and make sure it is mapped correctly to the Script step output.

JuhiPoddar_5-1786952597181.png

Execution details:

You can test the Action with different expiry dates to verify the result:

  • Expiry date before today → true

JuhiPoddar_6-1786955623546.png

  • Expiry date equal to today → false

JuhiPoddar_7-1786955658643.png

  • Expiry date after today → false

JuhiPoddar_8-1786955683426.png

I hope this helps!

Thank You!

Juhi poddar

 

Thank You!
Juhi Poddar