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

Hi Vijay.



  You can follow me and then you will see a message icon and can start a private chat and you can share your instance credentials I can look into it.


sorry , i cannot share my credentials . any other ways ?



On Thu, Sep 15, 2016 at 11:49 AM, abhi_r <community-no-reply@servicenow.com>


deepakgarg
ServiceNow Employee
ServiceNow Employee

Hi,



This might be helpful:


Client Script Date/Time Functions



Thanks,


Deepak.


PS: Hit like, Helpful or Correct depending on the impact of the response.


vijaysirangi
Kilo Contributor

Hi , thanks for response.



i will explain my requirement exactly .



when user selects some date in the calendar (as shown the varibale in the image above)   , that date or duration selected by him should be 48hrs from the time he is placing request , if   < 48hrs then a dialogue box shuld pop out saying that "Duration selected should be atleaset 48hrs minimum"/



please give the script for this .



thanks in Advance.


As others pointed you need to write an onChange client script on your LPAR variable and use Glide Ajax in your client script. Let me know if you need help in scripting.