When you select Planned Start Date on change form, validate if Planned Start Date is after 10 days of current date. If not display an error message below the field and clear the value selected.

Afrin12
Tera Contributor

When you  select  Planned Start Date on  change form, validate if Planned Start Date is after 10 days of current date. If not display an error message below the field and clear the value selected.

Not able to change the date.  Please help me with solution

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

Hi @N Afreen Afreen,

Please Create a Client script with the following configuration:

find_real_file.png

SCRIPT:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	var minutes_from_now = 14400;
	var date_obj = new Date(getDateFromFormat(newValue, g_user_date_time_format));
	
	var future_date = new Date(new Date().getTime() + minutes_from_now*60000);	
	
	if(date_obj < future_date){
		g_form.setValue('start_date', '');
		g_form.showFieldMsg('start_date', "Planned start date must be 10 days from now.", 'error');
		
	} else {
		g_form.clearMessages();
	}
}

Please mark this helpful/correct, if applicable.

Regards,
Muhammad
Servicenow Community MVP
Servicenow Developer MVP

Regards,
Muhammad

View solution in original post

2 REPLIES 2

MrMuhammad
Giga Sage

Hi @N Afreen Afreen,

Please Create a Client script with the following configuration:

find_real_file.png

SCRIPT:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	var minutes_from_now = 14400;
	var date_obj = new Date(getDateFromFormat(newValue, g_user_date_time_format));
	
	var future_date = new Date(new Date().getTime() + minutes_from_now*60000);	
	
	if(date_obj < future_date){
		g_form.setValue('start_date', '');
		g_form.showFieldMsg('start_date', "Planned start date must be 10 days from now.", 'error');
		
	} else {
		g_form.clearMessages();
	}
}

Please mark this helpful/correct, if applicable.

Regards,
Muhammad
Servicenow Community MVP
Servicenow Developer MVP

Regards,
Muhammad

asifnoor
Kilo Patron

Hi AFreen,

Refer to the below link where i have shared similar solutions. you can use one of those.

https://community.servicenow.com/community?id=community_article&sys_id=a26dac761b4e8010a59033f2cd4bc...

Mark the comment as a correct answer and also helpful if this has helped to solve the problem.