No Code Date Validations

I’ve in the past had to write some… cludgy date comparisons. I’m not proud of them. I’m just glad I didn’t have to look at them later.

Had I thought about what Mark Ragavan wrote about, it would have saved me probably days over my development time in the last 10 years.

Really, theres some common types of checks and actions for dates.

  • Is it in the past?
  • Is it within a window? e.g. After 7 days from now.
  • Is it after another date on the form?

To show this I’ll add some reproduction steps below. Start out with my ATF Scoped App;

  1. On your PDI import my “ATF” scoped app.
  2. URL: https://github.com/jacebenson/atf.git
  3. Change scope to “ATF”
  4. Goto maintain items, and look for “Test Item”

Now that you’re here we can quickly test this out.

Disallow past dates

  1. Create a UI Policy with the condition, Date Before Today. UI Policy
  2. Add a UI Policy action for the field Date and check the clear value checkbox. UI Policy
  3. Update the variable Date to have Example text of “Date cannot be in the past.” Variable

Try it out.

Now that you’ve seen it, it should be pretty clear how to apply this to a number of different situations. I just wanted to share as this is a great way for me to remember.

Further Reading: No Code dates validations thru Catalog UI Policies

unsplash-logoEric Rothermel

Edit this page

Avatar
Jace Benson
ServiceNow Developer

ServiceNow is my day job, JAMStack is my passion.