Scripting Help- How can I compare multiple dates and choose the one closest to today?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2025 12:29 PM - edited ‎03-05-2025 12:37 PM
I have a FD Flow created that I want to call a Flow Action from. I need to add a 'Script Step' in the flow Action that will do the following:
Look up all dates from a Date Field, on all Order Line Items, associated with a Customer Order.
Compare all those dates and return (as output) the date that is closest to today's date.
The input to the Flow Action will be the Customer Order
The output will be the date
Requirement:
Get all the dates from the field 'u_expected_date' on all Order Line Items, associated with a Customer Order. Compare those dates and return the date that is closest to today's day.
Help is greatly appreciated!!!
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 05:08 AM
Thank you for your response.
Would this be an Inline Script in the FD Flow, or code to put in the FD Action Script Step?
Please let me know.
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 06:26 AM
That will depend on your flow but the easiest way would probably be to put it in a Script step in an Action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 05:19 AM
you can create a script step and pass input to it.
Output will be a variable which is of type Date
Then this output you can use in next step
Use script shared by other members.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader