Date field variable restriction for current, past and able to select max 365 days from tomorrow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 10:18 PM
Hello,
i have a requirement for one of the catalog variable of date type field, where i should restrict the user on selecting present, past date and user should be able to select only max 365 days from date of selection that's from tomorrow, anyone help me out how this can be achieved.
Thankyou
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 10:23 PM
Hi @s_dinesh01 Write onChange Catalog Client Script on Date Variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var selectedDate = new Date(newValue);
var currentDate = new Date();
var minDate = new Date();
minDate.setDate(minDate.getDate() + 1);
var maxDate = new Date();
maxDate.setDate(maxDate.getDate() + 365);
if (selectedDate < minDate) {
g_form.addErrorMessage('The selected date cannot be in the past. Please choose a date from tomorrow onwards.');
g_form.setValue('your_date_variable_name', '');
} else if (selectedDate > maxDate) {
g_form.addErrorMessage('The selected date cannot be more than 365 days from today.');
g_form.setValue('your_date_variable_name', '');
}
}
Regards,
Sid
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 10:47 PM
Hi @s_dinesh01
You can simply write UI Policy with no code. Refer below link for explanation and examples
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