- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 05:51 AM
Hi all,
I have a catalog client script to prevent users from selecting a date in the past. But it is not fully working.
It now stops me from selecting any date, and error appears. past or future date.
Below is my script on a onChange client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//current date
var currentDateObj = new Date();
var currentDateStr = formatDate(currentDateObj, g_user_date_format);
var currentDateNum = getDateFromFormat(currentDateStr, g_user_date_format);
var startDateNum = getDateFromFormat(newValue, g_user_date_format);
if (startDateNum < currentDateNum) {
g_form.addErrorMessage("Date cannot be in the Past");
g_form.clearValue("day_month_year_start_time");
return false;
}
}
please advise
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 05:57 AM
Hi @Khalnayak ,
Please use my below working Scripts,just replace your variables.
onChange Catalog Client Script:-
1) Client Script for Future Date Validation:-
2) Past Date Validation:-
3) Common Client Callable Script Include:-
4) Script Include Code;-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 06:07 AM
Hi @Khalnayak,
I would suggests to use the Catalog client scripts to prevent users from selecting a date in the past.
No Code date validations through (Catalog) UI Policies
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 06:16 AM
Hi @Khalnayak ,
Try by using below script in script include.
previousDate:function(){
var startDate=this.getParameter('sysparm_date');
var gdt=new GlideDateTime(startDate);
var gdt2=new GlideDateTime();
if(gdt.compareTo(gdt2)=='-1'){
return false;
}else{
return true;
}
}
Thanks,
Gopi