Scripting Help- How can I compare multiple dates and choose the one closest to today?

ssellmeyer
Tera Guru

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!

 

7 REPLIES 7

@DrewW 

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!

That will depend on your flow but the easiest way would probably be to put it in a Script step in an Action.

Ankur Bawiskar
Tera Patron
Tera Patron

@ssellmeyer 

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.

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