onchange catalog client script code:
start date 'access_from' variable:
function
onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('servicerequest_ajax');
ga.addParam('sysparm_name', 'validate_fromto_dates');
ga.addParam('sysparm_startdate',newValue);
ga.addParam('sysparm_date_entered',newValue);
ga.addParam('sysparm_enddate',g_form.getValue('access_to'));
ga.getXMLAnswer(function(answer) {
//alert(answer);
var res=answer.split(':');
if (res[1]!="OK" ){
alert('Check dates--' + res[1]);
g_form.setValue('access_from', '');
return false;
}
});
}
end date 'access_to' variable:
function
onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('servicerequest_ajax');
ga.addParam('sysparm_name', 'validate_fromto_dates');
ga.addParam('sysparm_enddate',newValue);
ga.addParam('sysparm_date_entered',newValue);
ga.addParam('sysparm_startdate',g_form.getValue('access_from'));
ga.getXMLAnswer(function(answer) {
//alert(answer);
var res=answer.split(':');
if (res[1]!="OK" ){
alert('Check dates--'+res[1]);
g_form.setValue('access_to', '');
return false;
}
});
}
ajax script include code:
var
servicerequest_ajax = Class.create();
servicerequest_ajax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validate_fromto_dates: function(){
//--validate that end date>start date, dates not in
past
var
startDateEntered=new GlideDate();
var endDateEntered=new GlideDate();
var dateNow=new GlideDate();
var dateEntered=new GlideDate();
sReturn='RESULT:OK';
//alert('blah!');
var sd_param=this.getParameter('sysparm_startdate');
var ed_param=this.getParameter('sysparm_enddate');
var de_param=this.getParameter('sysparm_date_entered');
startDateEntered.setDisplayValue(sd_param);
endDateEntered.setDisplayValue(ed_param);
dateEntered.setDisplayValue(de_param);
var dateNowF=new GlideDate();
dateNowF.setDisplayValue(dateNow);
if(dateEntered<dateNowF){
sReturn='RESULT:date in
past entered';
}
//sReturn='SD:' + startDateEntered + ';ED:' +
endDateEntered + ';DE:' + dateEntered + ';DN:' + dateNowF + ';true/false=' +
(dateEntered>=dateNowF).toString();//--for testing
if (de_param==sd_param){
//--start date onchange script
sReturn=sReturn+ ':start date';
}
if (de_param==ed_param){
//--end date onchange script
sReturn=sReturn+ ':end date';
}
if (sd_param!='' && ed_param!=''){
if(endDateEntered<startDateEntered){
sReturn='RESULT:end date
must not be before start date';
}
}
return sReturn;
},
type: 'servicerequest_ajax'
});
Comments
Post a Comment