Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Restrict user to select date upto 3 months in Catalog item

ServiceNow SA
Kilo Guru

Hi Team,

I have a date field in my catalog item. I need user to select dates only upto 3 months from now.

For eg, If user is raising request today , he should only be able to select date till 21-Feb-2018 .Not more than that.

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron

Hi Sri,



Link Limit date selection in date field   has a UI policy part for limiting date selection possibly that would help & would be simplest one to set up.


View solution in original post

9 REPLIES 9

You can do via UI policy aslo. 

Hi Jaspal,

 

The link is not opening the community article for me. Can you please reshare the link?

 

Thank you in advance!

Try this:

 

community.servicenow.com/community?id=community_question&sys_id=15658baddbd8dbc01dcaf3231f961936

Prateek kumar
Giga Sage

This post should help you


Client Script Date/Time Functions


Prateek kumar
Giga Sage

Hello Sri


Try this:


SI:


Client callable: checked


Name:DateValidation



DateValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  validateDate: function() {


  var ActualEndDate = this.getParameter('sysparm_end_date');


  return gs.dateDiff(gs.now(),ActualEndDate, true)/(86400*90); //90days


  },



      type: 'DateValidation'


});



Client Script:



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


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


          return;


    }


alert('on change started');


var ga = new GlideAjax('DateValidation');


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


  ga.addParam('sysparm_end_date',g_form.getValue('u_new_date')); //give your field name to be validated


  ga.getXML(ProcessResult);



  function ProcessResult(response) {


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


    alert(answer);


    if (answer > 1)


  {


  g_form.clearValue('u_new_date'); //give your field name to be validated


  alert('End Date should not be in the Past 90 days.');



  }


  }


}