- 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 03:35 AM
yeah in date picker it was there but the date was getting selected
- 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 04:16 AM
Glad to know that my script worked.
Please mark response helpful as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader