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

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


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


The backslashes aren't necessary because the outside quotes are double quotes and the inside ones are single quotes.


true, just tried it and it works!