- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2023 07:54 PM
Hello, I'm trying to create a script or solution that would apply for the date variable type on all catalog items and would restrict users from selecting a date in the past. Does anyone know of a way to do this? Would like for the solution to be applied to the date variable type on all catalog items without having to apply it to each item individually. Thank you in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2023 08:23 PM
Hi @marrerocmm ,
You can write a onChange client script on date field to call a client script.
In that script include, create a function to check the past date something like this:
function isPastDate() {
var initDate= new GlideDateTime(this.getParameter('YOUR_DATE_PARAMETER'));
var today = new GlideDateTime();
}
if(initDate.compareTo(today)) {
gs.info('Past date is not allowed')
return true;
}
and in the client script check if the function returns true then, print an error message and return false.
Hope this helps!
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2023 08:23 PM
Hi @marrerocmm ,
You can write a onChange client script on date field to call a client script.
In that script include, create a function to check the past date something like this:
function isPastDate() {
var initDate= new GlideDateTime(this.getParameter('YOUR_DATE_PARAMETER'));
var today = new GlideDateTime();
}
if(initDate.compareTo(today)) {
gs.info('Past date is not allowed')
return true;
}
and in the client script check if the function returns true then, print an error message and return false.
Hope this helps!
Regards