Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Time fields validation

scottangehr
Giga Guru

Hello friends

Happy Knowledge week!  How all is well.

I have an ask that I'm having a slight issue trying to make happen.

I have a Record Producer with variables that I need to make sure each variable is after the next.

These fields are string fields with the validation regex as Time (00:00) 24 hr.

I need there to be a validation and error that the field entered is after the previous field.

scottangehr_0-1715017301499.png

Meal Out should be after Time In
Meal In should be after Time In & Meal Out
Time Out should be after Time In, Meal Out, & Meal In

 

I originally created these fields as Date/Time but the business only wanted times

7 REPLIES 7

magee
Tera Guru

Being that they are string fields, is sounds like you'll need to take the date selected and value entered and call a script include via ajax to do the date/time validation. If it doesn't validate, you'll have to throw an error on the field and clear the value. It's a little messy but seems doable.

 

If you can convince the customer to go w/ a date/time field, all you need are UI Policies. Winner!

I did try to convince them. 😂
I need to show that 17:30 is after 17:29, etc. There is no date needed.

So since no date is needed, then everything is expected to happen 'today'?

Meaning, I can't submit a request for a day in the past.

 

I only ask cause when doing the comparisons, the Date/Time API might need a date...maybe

When I did have them as Date/Time fields, I had a validation script which took care of this. 
They are using these as a time card punch correction form.

I was thinking/hoping there was a something similar to this for a numeric string in time format.

 

 

if (startTime.getTime() >= endTime.getTime()) {