How to restrict the past dates selection on date field

poornima batchu
Tera Expert

Hi all, 

I need to restrict the past dates selection on the date field (Start_date). Fo this I created a Ui policy in when to apply I gave condition as Start_date before Today.  In the scripting I have added a error message it's working fine but...if I open any existing cases in system that is already having the value of start_date it is showing up the error message on the case for the Active and Inactive cases also.

What is the solution so that the pop should show up only for Active cases where the start_date value is empty.

4 REPLIES 4

Community Alums
Not applicable

Hi @poornima batchu ,

Here is the Sample Script, please change to fit your requirement:

Script Include:


Name:DateValidation


Client callable: Checked



var DateValidation = Class.create();


DateValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  validateDate: function() {


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


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


  },


      type: 'DateValidation'


});



Client Script:



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


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


              return;


      }


      var ga = new GlideAjax('DateValidation');


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


      ga.addParam('sysparm_end_date',g_form.getValue('u_business_need_by_date'));//give your date field


      ga.getXML(ProcessResult);


     


     


      function ProcessResult(response) {


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


              if (answer < 0)


                      {


                      g_form.clearValue('u_business_need_by_date'); //give your date field


                      alert('Business need date should not be in the Past.');


                     


              }


      }


}

 

Also, watch this video : https://www.youtube.com/watch?v=gghIdFlxsDg

 

In this video I've explained how to restrict past/future date selection in date type field If you really like my effort please like this video, subscribe my channel and share to your friends. If you have any feedback, please write in the comment box.

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Please share details of what you tried and what is not working.

 

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

poornimabatchu_0-1688637521271.pngpoornimabatchu_1-1688637537679.png

 

In ui policy I tried this but this error message should not show up for the existing cases in the system where the  date value is already given

And what if you change the onLoad checkbox?

 

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn