- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 08:20 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 08:45 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 08:25 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 08:32 AM
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');
}
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 08:37 AM
answer = 2020-04-27 17:37:02
timezone = Europe/Berlin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2020 08:45 AM
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.