How to display error message next to a variable in the Service Catalog

johannes5
Giga Expert

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

1 ACCEPTED SOLUTION

manikorada
ServiceNow Employee
ServiceNow Employee

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');


View solution in original post

7 REPLIES 7

ahaz86
Mega Guru

Your Syntax is actually ok. I just recreated this on a demo instance and it worked fine. Try checking your error console [F12] for any potential errors.


Hi Alexander,



are you using a field or a variable?



Thanks,


Johannes


Hi Guys,



I am all set thanks, yes it was a typo just as Mani pointed out.



Thank you so much.


Johannes