- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi
I have two variables called Start date and End date on catalog form I need a validation on End date, the selected date should be mamimum within 7 days from Start date
Note: Data type for both the variables is Date/Time
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
no scripting required.
You can use Catalog UI policy for this.
Output:
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
2 weeks ago
Hi @raj99918 ,
You can write a onChange client script on end date to check the difference between start date and end date it should be maximum 7 days. (or please change in your question. I assumed Maximum difference between start date and end date should be maximum 7 days)
Write a below code onChange of endDate.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
// Get Start Date value
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
if (!start || !end) return; // Validate presence
// Convert to Date objects (ServiceNow Date/Time returns ISO 8601 format)
var startDate = new Date(start);
var endDate = new Date(end);
// Calculate difference in days
var timeDiff = endDate.getTime() - startDate.getTime();
var dayDiff = timeDiff / (1000 * 3600 * 24);
if (dayDiff > 7) {
g_form.showFieldMsg('end_date', 'End date must be within 7 days of Start date.', 'error');
g_form.setValue('end_date', ''); // clear invalid value
} else {
g_form.hideFieldMsg('end_date'); // Hide field message if within range
}
}
Thanks,
Bhimashankar H
-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
no scripting required.
You can use Catalog UI policy for this.
Output:
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
2 weeks ago
Thanks Sir jii @Ankur Bawiskar