- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 01:49 PM
Hi ServiceNow Community Developers
Do you know if there is a way to display an error message next the variable that you are trying to validate in the service catalog. In other modules like incident and problem I do this all the time with the fields however in SC it does not seem to work with variables. Here is my script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var servers = g_form.getValue('number_of_servers_lenovo');
servers = servers.trim();
var num = isNaN(servers);
if (num == true) {
alert ("Enter a numeric value for 'Servers - Lenovo' field");
g_form.showFieldMsg('number_of_servers_lenovo',"Enter a numeric value for 'Servers - Lenovo' field.",'error');
return false;
}
}
The alert part does work and the form does not get submitted which is good however the error message in red does not appear next the variable. I think maybe the showFieldMsg() is not supported in the SC module. If its not supported is there a way I can focus on the variable after issuing an alert message?
Please advise.
Thanks,
Johannes
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 02:00 PM
Johannes,
There is a syntax error in your script. Try something like:
g_form.showFieldMsg('number_of_servers_lenovo',"Enter a numeric value for \'Servers - Lenovo\' field.",'error');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 02:00 PM
Johannes,
There is a syntax error in your script. Try something like:
g_form.showFieldMsg('number_of_servers_lenovo',"Enter a numeric value for \'Servers - Lenovo\' field.",'error');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 02:09 PM
Hi Mani,
I fixed the syntax as you pointed out but the error message next to the variable still does not get displayed. I will continue to poke around.
Thanks,
Johannes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 02:25 PM
The backslashes aren't necessary because the outside quotes are double quotes and the inside ones are single quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 06:15 PM
true, just tried it and it works!