- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 10:44 AM
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).
Thank you for your anticipated help.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 12:56 AM
It Is working fine in my pdi @Hola Ola
Refer below link
You can also write onChange Client script
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 11:21 AM
Preventing date selection involves DOM manipulation which is not so good practice. Instead, create a UI policy with conditions as below:
- Date<Date variable name> is before 7 days OR Date<Date variable name> is after 10 days
Create a Ui Policy action to clear the field value and display a field message if the above condition is met.
This will simply the logic and keep the solution clean.
Hit the Accept Solution button if the above solution helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 01:08 PM
Hello @Ravi Peddineni
Thank you for your response. However, it is still not working as desired. Perhaps something that I'm doing wrong.
I have the conditions this way:
Date field<variable_name>Relative>After>7>Days>From Now
Also, I should mention that I want the days that can be chosen to ONLY be between 7days and 14days (just a 2-week period) - Nothing Less and Nothing More
Script:
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'));
}
Again, thank you for your assitance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 01:32 PM
There's a syntax error in your code. Below is the corrected code:
function onCondition() {
g_form.clearValue('period_duration_required_for_the_requested_access'); //Did not use the single quotes in your code
g_form.showErrorBox('period_duration_required_for_the_requested_access', getMessage('Date should be 7 - 14 days in
the future'));
}
Also make sure to use below conditions on UI Policy:
Suggestion: To avoid scripting, Create a UI Policy Action and configure as shown below:
Hit the Accept Solution button if the above solution helped you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 03:24 PM
Hello @Ravi Peddineni
Apologies for the bother, something is still not right here.
My UI Policy Action only has these fields, which limits my configuration option (unless I don't know how to get the extra fields as shown in your example)
Also, here are my Conditions, as shown by you:
And my Script:
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'));
}
None seem to be working.