- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi all,
I am trying to configure a Date variable on a Catalog Item form so users can only select a date that is at least two weeks out from the current date. Using a Catalog Client Script, I tried scripting this function, which gives me no errors but seems to not change anything on the form.
Can anyone take a look at my script and tell me what I might be doing wrong?
Example: highlighted dates should be grayed out and not selectable:
My Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
@CesarV_ I believe you dn't need client script in this case, did you try UI policy.
The condition should be <date variable> "Relative (operator) after 14 Days from now".
Once you select the variable and operator as "relative", you will get other options to select. This way you can achieve this without script login.
After the condition, in the run script under "execute if true" , you can throw and alert or clear the field if earlier dat is selected.
Please mark the answer correct/helpful accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I'm sorry, I am relatively new to ServiceNow, are I doing this in System UI>UI Policies, or Under the Catalog UI Policies within the Catalog Item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
no scripting required and when you use UI policy you need not worry on the date format as well.
UI policy will handle that for you.
check response from @RaghavSh for that UI policy condition
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @CesarV_ , I had achieved something similar in my recent project.
I had used the onChange() client script instead of the onLOad().
Here is the script-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var selectedDate = new Date(newValue);
var today = new Date();selectedDate.setHours(0, 0, 0, 0);
today.setHours(0, 0, 0, 0);var twoWeeksLater = new Date(today);
twoWeeksLater.setDate(today.getDate() + 14);if (selectedDate < twoWeeksLater) {
g_form.addErrorMessage("Please select a date at least 2 weeks from today.");
g_form.clearValue('your_date_field');
}
}
replace field names with your actual field name.
If this solution helped you Please Mark this solution as accepted and helpful as it will be helpful for other users as well.
Best Regards.
Saurabh V.
