how to check , date and time entered by user is 48hours from the current time .

vijaysirangi
Kilo Contributor

find_real_file.png

please post if any one has the script for it .

1 ACCEPTED SOLUTION

Please check your instance. I have created a new onchnage client script and script include. It is working as expected.


onChange:


function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }


  var ga = new GlideAjax('ValidateDate');


  ga.addParam('sysparm_name','dateValidation');


  ga.addParam('sysparm_date',newValue);


  ga.getXML(CallBack);



  function CallBack(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  if(answer=='true'){


  alert("pls select atleast 48hrs or more   from now");


  g_form.setValue('lpar_refreshed','');


  }


  }


}


Script include:


var ValidateDate = Class.create();


ValidateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  dateValidation: function(){


  return (gs.dateDiff(gs.nowDateTime(),new GlideDateTime(this.getParameter('sysparm_date')), true)/3600<48);


  },


  type: 'ValidateDate'


});


View solution in original post

27 REPLIES 27

Abhinay Erra
Giga Sage

Do you have a personal developer instance? I will look into it.


https://dev22210.service-now.com/navpage.do




user name : admin


pw: vijay5484




u can login into it and i created a category caleld Unix items , in it i


created a field with name i need.

















for this field , when user selects any date and time , then script should


check whether that selected date time is 48hrs from the time he is


selecting . if not then a dialogue box saying pls select atleast 48hrs or


more from now .















On Thu, Sep 15, 2016 at 12:03 PM, abhi_r <community-no-reply@servicenow.com>


Please check your instance. I have created a new onchnage client script and script include. It is working as expected.


onChange:


function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }


  var ga = new GlideAjax('ValidateDate');


  ga.addParam('sysparm_name','dateValidation');


  ga.addParam('sysparm_date',newValue);


  ga.getXML(CallBack);



  function CallBack(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  if(answer=='true'){


  alert("pls select atleast 48hrs or more   from now");


  g_form.setValue('lpar_refreshed','');


  }


  }


}


Script include:


var ValidateDate = Class.create();


ValidateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  dateValidation: function(){


  return (gs.dateDiff(gs.nowDateTime(),new GlideDateTime(this.getParameter('sysparm_date')), true)/3600<48);


  },


  type: 'ValidateDate'


});


Hello Abhinay,



Can we exclude weekends from this. For example, if a user is placing request on Friday then it should not allow Saturday and Sunday. The date should be selected on Tuesday.



Thanks & Regards,


Jag.


Yes you can. You will have to use schedules for this. See GlideSchedule API.


http://wiki.servicenow.com/index.php?title=Scoped_GlideSchedule_API_Reference#gsc.tab=0