Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to showFieldMsg onLoad and onChange client Script ?

Kevin Smith2
Giga Expert

Hello Experts,

How can I show a field message onLoad and onChange in client script.

Here is my script:

function onLoad() {
	var timezone = g_form.getDisplayBox('u_time_zone').value;
	var ga = new GlideAjax('EServUtils');
	ga.addParam('sysparm_name', 'setDateTimeZone');
	ga.addParam('sysparm_time_zone', timezone);
	ga.getXML(getDateTimeZone);
	
	function getDateTimeZone(response) {
		var answer = response.responseXML.documentElement.getAttribute('answer').toString();
		g_form.showFieldMsg('u_required_by','Current date/time for service location is ' + answer + ' (Time Zone: ' + timezone + ')'+', please select the date/time accordingly.','info');
	}
	
}

Please let me know.

Thanks

Kevin

1 ACCEPTED SOLUTION

Ok, I see that your script is currently onload of the form, to make it work onchange as well, copy the same script and run it onchange . Onchange script will run onload also unless stopped, so comment the isLoading check and you should be fine.

-Anurag

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

I think timezone will not be accessible in the call back function, out of scope.

And where you are concatenating answer, use answer.toString();

Rest should be fie 🙂

-Anurag

-Anurag

vkachineni
Kilo Sage

See what you are getting in the call back

 

function getDateTimeZone(response) {
		var answer = response.responseXML.documentElement.getAttribute('answer').toString();
alert("answer =" + answer);
alert("timezone =" + timezone);
		g_form.showFieldMsg('u_required_by','Current date/time for service location is ' + answer.toString() + ' (Time Zone: ' + timezone + ')'+', please select the date/time accordingly.','info');
	}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

answer = 2020-04-27 17:37:02

timezone = Europe/Berlin

Ok, I see that your script is currently onload of the form, to make it work onchange as well, copy the same script and run it onchange . Onchange script will run onload also unless stopped, so comment the isLoading check and you should be fine.

-Anurag