Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Restrict past date in Date field - Onchange client script

chanikya
Kilo Sage

Hi,

i have BR script , it is working fine , there is no problem with BR script, i would like to see this functionality in client script

CLIENT SCRIPT -ONCHANGE 

BR script:  how can i write it into Client Script

var today= new GlideDateTime();
var past=new GlideDateTime(current.u_review_date);
var todaydate=today.getLocalDate();
var pastdate=past.getLocalDate();
if(pastdate.before(todaydate))
{
gs.addInfoMessage("Please don't select past date");
current.u_sunset_review_date="NULL";
current.setAbortAction(true);
}

1 ACCEPTED SOLUTION

Shashikant Yada
Tera Guru

You can follow below link, using Script Include and Client script will resolve your issue.

https://community.servicenow.com/community?id=community_question&sys_id=abd88f61db5cdbc01dcaf3231f9619f5

Thanks
Shashikant

Hit Helpful or Correct on the impact of response.

View solution in original post

21 REPLIES 21

Can you try with Script Include and Client script which I provided above.

yes..Thanks for that.

i have tried with that , it is working successfully...there is no problem with that.

 

i just trying to get result without using Script Include..................

Ok, Hit Helpful or Correct on the impact of response 🙂

Hi Chanikya,

Any updates on this?

Hi,

Please write below code in onSubmit() client script.

 

function onSubmit(){
	var now = new Date();
	now = formatDate(now, g_user_date_time_format);
	var x = g_form.getValue('u_duedate');
	
        alert("now.."+now+" "+"selected date.."+x);
	
        now = getDateFromFormat(now, g_user_date_time_format);
	
	x= getDateFromFormat(x, g_user_date_time_format);
	
	if (x<now) {
		alert('Selected date is in the past.');
		
		return false;
	}
	
}