Adding a countdown timer in InfoMessage

brysonelson
Kilo Contributor

Hello,

I am attempting to display an info message on a form with a number that will countdown to a form reload, however the number is not changing once the message shows.

This is a getXML callback for reference.

Can info messages not handle something like this?

Here is my code:

function handleResponse(response) {
	var timer = 3;
	var userAnswer = response.responseXML.documentElement.getAttribute('answer');
	var answer = JSON.parse(userAnswer);
	setInterval(function() {
		timer--;
	}, 1000);
	g_form.addInfoMessage('The form will automatically reload in ' + timer + ' seconds');
	setTimeout(reloadForm, 3000);
}

function reloadForm() {
	location.reload();
}
1 ACCEPTED SOLUTION

Elijah Aromola
Mega Sage

Change your script to: 

function handleResponse(response) {
	var timer = 3;
	var userAnswer = response.responseXML.documentElement.getAttribute('answer');
	var answer = JSON.parse(userAnswer);
	setInterval(function() {
		timer--;
                g_form.clearMessages();
                g_form.addInfoMessage('The form will automatically reload in ' + timer + ' seconds');
	}, 1000);
	
	setTimeout(reloadForm, 3000);
}

function reloadForm() {
	location.reload();
}

You can get rid of the .clearMessages() if you want each message to show. 

Please mark this as correct/helpful if it resolved your issue!

View solution in original post

2 REPLIES 2

Elijah Aromola
Mega Sage

Change your script to: 

function handleResponse(response) {
	var timer = 3;
	var userAnswer = response.responseXML.documentElement.getAttribute('answer');
	var answer = JSON.parse(userAnswer);
	setInterval(function() {
		timer--;
                g_form.clearMessages();
                g_form.addInfoMessage('The form will automatically reload in ' + timer + ' seconds');
	}, 1000);
	
	setTimeout(reloadForm, 3000);
}

function reloadForm() {
	location.reload();
}

You can get rid of the .clearMessages() if you want each message to show. 

Please mark this as correct/helpful if it resolved your issue!

Please help me

 

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