- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 01:16 AM
Need to create a client script to validate that date I enter there should not be more than 30 days from today, There is another field called Impact. Is user selects any impact than date should not be more than 7 days from today.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 01:24 AM
Hi Sai,
You can do this using 2 UI policies as well. No need of using client script.
UI Policy for Impact is empty
Condition 1: Impact is empty AND //you can remove this condition if not needed.
Condition 2: Date before Today OR // My guess is you dont need dates from the past
Condition 3: Date relative after 30 days from now
UI Policy for Impact is NOT empty
Condition 1: Impact is empty AND //you can remove this condition if not needed.
Condition 2: Date before Today OR
Condition 3: Date relative after 7 days from now
Add below script(In Script section select Run Script is True and add code in Execute if True) in both the policies to clear the date field value and to show error message.(if needed)
function onCondition() {
g_form.clearValue('date_field_name');
g_form.showErrorBox('date_field_name', 'Select a date from today upto the next 30 days', 'error');
return false;
}
Sample snapshot:
Regards,
Shubham
Shubham Tipnis
ServiceNow Enthusiast
⭐️ 3x Rising Star (2022–2024) – ServiceNow Community
Sharing insights, use cases & real-world learnings from the Now Platform
Always learning. Always building.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 02:22 AM
This solution of 2 UI Policies worked perfectly for me. Thanks !.
Also, thank you for the script which you provided.