Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Make an warning message disappear after 5 seconds

Tejas16
Tera Contributor

I am using onChange Client Script.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var originalValue = g_form.getValue("end_date");
if (isLoading || newValue === '' || originalValue === '') {
return;
}

if (new Date(newValue) > new Date(originalValue)) {
// alert("End date: " + originalValue + " start Date:" + newValue);
g_form.setValue("end_date", newValue);
g_form.showFieldMsg('end_date', "The selected Date (" + originalValue + ") was before the selected Start Date. End Date has been reset to the Start Date ", 'warning');
}

}

 I want warning message to be clear out after 5 seconds as after script runs is finished.

How can I achieve this functionality?  

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @Tejas16,

 

Try this updated scripts and make sure to set Isolate scripts check box to false.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	var originalValue = g_form.getValue("end_date");
	if (isLoading || newValue === '' || originalValue === '') {
		return;
	}

	if (new Date(newValue) > new Date(originalValue)) {
		// alert("End date: " + originalValue + " start Date:" + newValue);

		g_form.setValue("end_date", newValue);
		g_form.showFieldMsg('end_date', "The selected Date (" + originalValue + ") was before the selected Start Date. End Date has been reset to the Start Date ", 'warning');
	}
	window.setTimeout(hideFieldMessages, 5000);


}

function hideFieldMessages() {
	g_form.hideFieldMsg("end_date"); // updated your field name to end_date

}

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

View solution in original post

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @Tejas16,

 

Try this updated scripts and make sure to set Isolate scripts check box to false.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	var originalValue = g_form.getValue("end_date");
	if (isLoading || newValue === '' || originalValue === '') {
		return;
	}

	if (new Date(newValue) > new Date(originalValue)) {
		// alert("End date: " + originalValue + " start Date:" + newValue);

		g_form.setValue("end_date", newValue);
		g_form.showFieldMsg('end_date', "The selected Date (" + originalValue + ") was before the selected Start Date. End Date has been reset to the Start Date ", 'warning');
	}
	window.setTimeout(hideFieldMessages, 5000);


}

function hideFieldMessages() {
	g_form.hideFieldMsg("end_date"); // updated your field name to end_date

}

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Instead of using 

window.setTimeout(hideFieldMessages, 5000);

we only require setTimeout(hideFieldMessages,5000);