How to compare Expiry Date with Today Date in a Custom Action and return Boolean value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
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:
If Expiry Date is before today, return TRUE.
If Expiry Date is today, return FALSE.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
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.
2. Add a Script step
- 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.
Execution details:
You can test the Action with different expiry dates to verify the result:
- Expiry date before today → true
- Expiry date equal to today → false
- Expiry date after today → false
I hope this helps!
Thank You!
Juhi poddar
Juhi Poddar