How can I limit a DATE field from being populated with invalid dates

Hola Ola
Giga Guru

Happy Friday All, 

 

How can I prevent users from populating a DATE field with a date No Less That 5 Business Days (7 Total days from today) and No More Than 10 Business days (14 Total days from today).

 

HolaOla_0-1726249266144.png

Thank you for your anticipated help. 

1 ACCEPTED SOLUTION

It Is working fine in my pdi @Hola Ola 

Refer below link

https://www.servicenow.com/community/developer-articles/no-code-date-validations-through-catalog-ui-... 

 

You can also write onChange Client script 

https://www.servicenow.com/community/itsm-forum/if-end-date-is-more-than-10-business-days-alert-shou...

 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

11 REPLIES 11

Hi @Hola Ola 

Add Below condition

VoonaRohila_0-1726260174953.png

In Execute if False part of the code, Use your script to clear the value.

function onCondition() {
g_form.clearValue(period_duration_required_for_the_requested_access);
g_form.showErrorBox('period_duration_required_for_the_requested_access', getMessage('Date should be 7 - 14 days in the future'));
}

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hello @Voona Rohila ,

Thanks for your response and my sincere apologies for the bother. This is still not working as I had hoped. 

I'm sure I'm not doing something right here.

 

I used the script you provided and the Conditions. Am I missing something in the Execute if false box?

HolaOla_2-1726266585247.png

__________________________________________________________________________

HolaOla_3-1726266656601.png

 

 

Use below code in Execute if false.

function onCondition() {
g_form.clearValue(period_duration_required_for_the_requested_access);
g_form.showErrorBox('period_duration_required_for_the_requested_access', getMessage('Date should be 7 - 14 days in the future'));
}

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hello @Voona Rohila 

Thank you for sticking with me. 

The issue I'm still having is demonstrated below:

 

Pic 1: I have the field showing the message

HolaOla_0-1726334458517.png

 

PIC 2: The Field still accepts a date that is only 3 days away (I am trying to restrict it to no earlier than 7 days and no later than 14 days).

HolaOla_1-1726334658646.png

Please tell me what I'm doing very wrong. 

 

@Hola Ola  - I will implement and share the details.

Your date field should accept after 7-14 days only right?


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP