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.

Due Date on Problem task form should be restricted to only 2 months.

VijayKummamuru
Tera Expert

Due Date on Problem task form should be restricted to only 2 months and user should not be able to select past date.

 

 

Please guide me on this requirement

 

 

 

 

@itsm @developer @Problem 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@VijayKummamuru 

you can use 2 UI policies

1) 1st one like this to block past date using UI policy and then use Scripts to show info/error message

AnkurBawiskar_0-1742831226082.png

 

OR

use this onChange client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	g_form.hideErrorBox('end_date');
	if (newValue != oldValue) {
		var RightNow = new Date().getTime();
		var end = new Date(g_form.getValue('end_date')).getTime();
		if (end < RightNow) {
			g_form.clearValue('end_date');
			g_form.showFieldMsg('end_date', 'Planned end date must be after the current date', 'error', true);
		}
	}
}

2) another UI policy for restricting 2 months -> something similar in the condition

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@VijayKummamuru 

you can use 2 UI policies

1) 1st one like this to block past date using UI policy and then use Scripts to show info/error message

AnkurBawiskar_0-1742831226082.png

 

OR

use this onChange client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	g_form.hideErrorBox('end_date');
	if (newValue != oldValue) {
		var RightNow = new Date().getTime();
		var end = new Date(g_form.getValue('end_date')).getTime();
		if (end < RightNow) {
			g_form.clearValue('end_date');
			g_form.showFieldMsg('end_date', 'Planned end date must be after the current date', 'error', true);
		}
	}
}

2) another UI policy for restricting 2 months -> something similar in the condition

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

VijayKummamuru
Tera Expert

Thank you verymuch @Ankur Bawiskar