- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:12 AM
i have a date type variable and date should be within the last 29 days!! If customer provides invalid date, present an ERROR message "Please choose a date within the 30 days. I need to use the onChange client script. Can someone please help me with it?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 03:51 AM
you cannot restrict dates in date picker.
since yours is date variable; update as this
onChange is running on which variable? it should be sap_restore_point right since user is selecting that
you want to compare restore point date with (today date-29)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var todayDate = new Date();
todayDate.setDate(todayDate.getDate() - 29);
var selected_dateNum = new Date(newValue);
if(selected_dateNum.getTime() < todayDate.getTime() ) {
g_form.addErrorMessage('Date should be 29 days from Expected date');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:44 AM
Hi,
you can easily handle this using UI policy
No Code date validations through (Catalog) UI Policies
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 03:17 AM
Hi ankur, i tried with ui policy but it its selecting the date so if for eg i am selecting todays date then 17th jan should not get selected and 16th should but it is currently not happening.
i tried an on change client script : can you please suggest where is it wrong?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var restore_point = new Date(getDateFromFormat(g_form.getValue("sap_restore_point"), g_user_date_time_format));
restore_point.setDate(restore_point.getDate() - 29);
var restore_pointStr = formatDate(restore_point,g_user_date_time_format);
var restore_pointNum = getDateFromFormat(restore_pointStr,g_user_date_time_format);
var selected_dateNum = getDateFromFormat(newValue,g_user_date_time_format);
if(selected_dateNum < restore_pointNum ) {
g_form.addErrorMessage('Date should be 29 days from Expected date');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 03:31 AM
Hi,
you cannot remove those dates from date picker.
but can only validate those
What came in alert for those dates?
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader