We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Start Date cannot be in the past

sonita
Giga Guru

What I'm trying to accomplish is that: Start Date cannot be in the past

This is my script:

but my problem is that , I need to be able to select today's date as well, but with this script it doesn't let me .

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

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

          return;

    }

var today = new Date().getTime();

 

  var start = new Date(g_form.getValue('start_date'));

  g_form.hideFieldMsg('start_date', true);

  if(start<today)

  {

  g_form.showFieldMsg('start_date','Start date cannot be in the past','error');

  g_form.clearValue('start_date');

  }

}

1 ACCEPTED SOLUTION

Harneet Sital
Mega Sage

Write a UI policy with the following condition :



Capture.PNG



Write following script :


function onCondition() {


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


      alert("Enter valid date");


}



This is working fine for me. Try it.


View solution in original post

5 REPLIES 5

Works as expected. Thanks   a lot !!