end date cannot be before start date
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-14-2022 07:39 AM
Hi, I need a catalog client script on end date cannot be before start date and start date should be after 72 hours.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-14-2022 07:54 AM
Hello,
I think it is better to do it with UI policy as below:-
But if you want to do it via catalog client script do the below:-
Client Script:-
Replace the start date and end date variable name
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('DateTimeAjax');
ga.addParam('sysparm_name', "compareDates");
ga.addParam('sysparm_start', g_form.getValue('start_date')); // start variable
ga.addParam('sysparm_end', g_form.getValue('end_date')); // end variable
ga.getXMLAnswer(function(answer){
if(answer != ''){
alert('End date should be more that 3 days from start date');
g_form.clearValue('end');
}
});
//Type appropriate comment here, and begin script below
}
Script Include: It should be client callable
var DateTimeAjax = Class.create();
DateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareDates: function(){
var start = new GlideDateTime(this.getParameter('sysparm_start'));
var end = new GlideDateTime(this.getParameter('sysparm_end'));
start.addDays(3);
if(end.getNumericValue() < start.getNumericValue()){
return 'End Date should be more tha 3 days from start';
}
return '';
},
type: 'DateTimeAjax'
});
Please mark my answer as correct based on Impact.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-12-2023 07:18 PM
@Saurav11 Your answer is correct. @Pettam Deepthi Please mark Saurav's answer as correct